Forum Discussion
hrh_dash
Sep 07, 2022Iron Contributor
Macro to input values for lastcol with regards to a specific row
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!
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