I am currently using the code below to insert a column near the last occupied cell.
VBA Code:
Sub xx()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = Sheet1 ' Data is 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 = "New Column Title"
End With
End Sub
Currently the output of this is (using example data)
I would like the output to be
Is there anyway to edit my code to achieve this?
VBA Code:
Sub xx()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = Sheet1 ' Data is 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 = "New Column Title"
End With
End Sub
Currently the output of this is (using example data)
Example Sheet.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Description | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | New Column Title | ||
2 | 1 | 1 | 1 | 1 | 1 | 1 | ||||
3 | AAAA | X | X | |||||||
4 | BBBB | X | X | X | ||||||
5 | CCCC | X | X | |||||||
6 | DDDD | X | X | X | X | |||||
7 | EEEE | X | X | |||||||
8 | FFFF | X | X | X | X | |||||
9 | GGGG | X | X | |||||||
10 | ||||||||||
Sheet1 |
I would like the output to be
Example Sheet.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Description | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | New Column Title | ||
2 | 1 | 1 | 1 | 1 | 1 | 1 | ||||
3 | AAAA | X | X | |||||||
4 | BBBB | X | X | X | ||||||
5 | CCCC | X | X | |||||||
6 | DDDD | X | X | X | X | |||||
7 | EEEE | X | X | |||||||
8 | FFFF | X | X | X | X | |||||
9 | GGGG | X | X | |||||||
10 | ||||||||||
11 | ||||||||||
Sheet1 (3) |
Is there anyway to edit my code to achieve this?