I want to insert a new column (with the name) after last column with data.
i tried using the below code by writing it in VBA module, however it does not work.
[
Sub add_column()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = Sheet1 ' NOTE: Change this if your data is not in Sheet1.
With ws
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "XXXX"
.Cells(1, LastCol + 2).Value = "YYYY"
End With
End Sub
]
i tried using the below code by writing it in VBA module, however it does not work.
[
Sub add_column()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = Sheet1 ' NOTE: Change this if your data is not in Sheet1.
With ws
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "XXXX"
.Cells(1, LastCol + 2).Value = "YYYY"
End With
End Sub
]