Hi guys! Long time reader, first time poster.
Getting very frustrated with my VBA so any help is appreciated.
In my worksheet "Paste Data", I have a string of text in column G and need to use the LEFT formula to find and copy the text before the character " - " into column H.
My VBA code works, but only for the first row. When I try to use various VBA to copy this down to all the cells in column H, the results are all the same as the results in cell H2. Understandably because the code is always directing the formula back to cell G2.
How can I edit the code so that a) the results in cell H3 are dependent on G3, and H4 is dependent on G4 etc. and b) copy this down the column as needed?
Dim c As Range
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "G").End(xlUp).Row
For Each c In Range("H2:H" & Lastrow)
c.Value = Left(Worksheets("Paste Data").Range("G2"), (Application.WorksheetFunction.Find(" - ", Worksheets("Paste Data").Range("G2"), 1) - 1))
Next
Thanks for your help!
Getting very frustrated with my VBA so any help is appreciated.
In my worksheet "Paste Data", I have a string of text in column G and need to use the LEFT formula to find and copy the text before the character " - " into column H.
My VBA code works, but only for the first row. When I try to use various VBA to copy this down to all the cells in column H, the results are all the same as the results in cell H2. Understandably because the code is always directing the formula back to cell G2.
How can I edit the code so that a) the results in cell H3 are dependent on G3, and H4 is dependent on G4 etc. and b) copy this down the column as needed?
Dim c As Range
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "G").End(xlUp).Row
For Each c In Range("H2:H" & Lastrow)
c.Value = Left(Worksheets("Paste Data").Range("G2"), (Application.WorksheetFunction.Find(" - ", Worksheets("Paste Data").Range("G2"), 1) - 1))
Next
Thanks for your help!