I have a workbook with a column of 1's and -1's. I want to go through with a loop and alter that data in two instances. If the column produces (1,-1,1) or (-1,1,-1) I then want it to change that third value to be equal to the second value and move on down the column. I have some VBA to accomplish this but it does nothing when I run it. It might be something simple or I might be way off base, either way any suggestions would be appreciated. Here is what I have.( Two options)
Sub Alter_data()
Dim cell As Range
Dim Rng As Range
Dim x As Integer
Do While (x - 1) <> (x - 2) And (x - 2) = x
x = x + 1
If (x - 1) <> (x - 2) And (x - 2) = x Then
x = (x - 1)
End If
Loop
End Sub
OR
Sub Alter()
Dim i As Integer
Dim r As Range, cell As Range
Set r = Range("B2:B4248")
For Each cell In r
If (i - 1) <> (i - 2) And (i - 2) = i Then
i = (i - 1)
Else: i = i
End If
Next
End Sub
Bookmarks