I have been trying to work on a small macro to help me quickly copy a value down one cell based on a string of text in the adjacent column. I have used the macro recorder to just select the next cell and then copy down, however, with the amount of data that is in the query, that would be a lot of code and a long time to record. I am thinking I need to use a loop or an If-Then function, but I am not sure how to go about setting that up. I have looked over many of the threads here however, when I try to replace suggested code with my range it doesn't work.
It also doesn't need to be based on the string "Temperature Wtr" either. If I could figure out how to just copy down the Chlorine, Free value one cell all the way down I would like that as well. Essentially, all I am wanting is for each row to replace the "Temperature Wtr" value/result with the "Chlorine, Free" value/result without having the need to select each cell and copy down one at a time.
CodePudding user response:
I hope I get it right. This makro will copy the "Result" value of "Chlorine, Free" one cell below for each cell that contains the text "Chlorine, Free" on column "E".
Public Sub DoThis()
Dim c As Range
For Each c In ActiveSheet.Range("E:E").Cells
If (c.Value = "Chlorine, Free") Then
c.Offset(1, 1).Value = c.Offset(0, 1).Value
End If
' We dont want to check more cells then necessary
If (c.Row > ActiveSheet.UsedRange.Rows.Count) Then
Exit For
End If
Next
End Sub