Sep 07 2022 08:17 AM
Would like to seek advise for a macro to input values in the next column of lastcol; ie lastcol.offset(0, 1).
For example if there is a value in A1, when the macro executed, the value will be populated in A2.
Currently, the code below would populate data in cell B32. The column is correct but the row no is incorrect
Dim lastCol As Long
Dim ws as Worksheet
Set ws = Sheet4
lastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.Range("A3" & lastCol).Offset(0, 1).value = "Yes"
Thanks for the help in advance!
Sep 07 2022 08:25 AM
Solution@hrh_dash If you want to add data to right after last column of a specific row then try-
Sub AddToLastCol()
Dim lastCol As Long
Dim ws As Worksheet
Set ws = Sheet4
lastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.Cells(1, lastCol) = "Yes"
End Sub
Sep 07 2022 08:34 AM
Sep 07 2022 08:40 AM
Sep 07 2022 09:44 PM
Sep 07 2022 08:25 AM
Solution@hrh_dash If you want to add data to right after last column of a specific row then try-
Sub AddToLastCol()
Dim lastCol As Long
Dim ws As Worksheet
Set ws = Sheet4
lastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.Cells(1, lastCol) = "Yes"
End Sub