Hi all,
I am trying to write a macro that will move data from one cell to another, based on specific criteria.
I have data in columns A and B. Column A contains either the number 2 or 3. The macro goes down column A, and if it finds a 2, it should move the contents of the same row and column B into column C. And if it finds a 3 in column A, it should move the contents of the same row and column B into column D.
However, the code that I've come up with (from info online etc), moves the data from column A, not column B.
This is what I have so far:
Sub Movetest()
Dim r As Range
For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
If r.Value Like "[2]" Then
r.Cut r.Offset(-1, 3)
End If
If r.Value Like "[3]" Then
r.Cut r.Offset(-1, 4)
End If
Next
MsgBox "done"
End Sub
I also attach a small screenshot to indicate what the data looks like. I hope I've explained it well enough for someone to be able to help.
If anyone can help, I will be extremely greatful.
I am trying to write a macro that will move data from one cell to another, based on specific criteria.
I have data in columns A and B. Column A contains either the number 2 or 3. The macro goes down column A, and if it finds a 2, it should move the contents of the same row and column B into column C. And if it finds a 3 in column A, it should move the contents of the same row and column B into column D.
However, the code that I've come up with (from info online etc), moves the data from column A, not column B.
This is what I have so far:
Sub Movetest()
Dim r As Range
For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
If r.Value Like "[2]" Then
r.Cut r.Offset(-1, 3)
End If
If r.Value Like "[3]" Then
r.Cut r.Offset(-1, 4)
End If
Next
MsgBox "done"
End Sub
I also attach a small screenshot to indicate what the data looks like. I hope I've explained it well enough for someone to be able to help.
If anyone can help, I will be extremely greatful.