Reputation: 23
I have two columns that need to have their contents combine. I want the combining to occur on every row of form.
With Cells(PoleRow, 25) = Cells(PoleRow, 25).Value & " / " & Cells(PoleRow, 123).Value
End With
With this code, it does not error out but it also does not do anything. I want to combine everything in column 123 into column 25.
Upvotes: 0
Views: 50
Reputation: 96
You just can't do it in one lane :)
Earlier you should declare starting row and last row for which you want to iterate.
For PoleRow=1 to 125 ' decalring start row = 1 and last row, you can also declare last row by VBA code
With Cells(PoleRow, 25)
Cells(PoleRow,25) = Cells(PoleRow, 25).Value2 & " / " & Cells(PoleRow, 123).Value2
End With
Next PoleRow
How to declare last row/coll: https://www.thespreadsheetguru.com/blog/2014/7/7/5-different-ways-to-find-the-last-row-or-last-column-using-vba
Upvotes: 0
Reputation: 43575
Try to make the code as simple as possible. E.g., write the left concatenated part to a string and pass the string to a value. Then it looks maintainable and eas to understand:
Sub TestMe()
Dim poleRow As Long
poleRow = 1
With Worksheets(1)
Dim union As String
union = .Cells(poleRow, 25) & " / " & .Cells(poleRow, 123)
.Cells(poleRow, 25) = union
End With
End Sub
Upvotes: 1