I'm using a script I found in a post from RickXL to auto-find the last column and add header name. This worked perfectly, and now I want to set the width of each new column to the values shown. I've tried with and without the Columns.EntireColumn.Select method, along with Columns.ColumnWidth = ** but no matter which combination I use, all columns are resized to 10. I'm a beginner and would appreciate any help possible. I also have some other actions that I would like to perform on the last 3 new columns which I've already created via another macro, but am unsure how to insert them into this one correctly. Thank you!
Sub InsertColumnAfterLastColumn()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = Sheet4
With ws
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Observations"
Columns.EntireColumn.Select
Columns.ColumnWidth = 30
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Deviations"
Columns.ColumnWidth = 20
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Potential Debit Amount"
Columns.ColumnWidth = 10
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Debit Amount"
Columns.ColumnWidth = 10
End With
End Sub
Sub InsertColumnAfterLastColumn()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = Sheet4
With ws
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Observations"
Columns.EntireColumn.Select
Columns.ColumnWidth = 30
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Deviations"
Columns.ColumnWidth = 20
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Potential Debit Amount"
Columns.ColumnWidth = 10
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Debit Amount"
Columns.ColumnWidth = 10
End With
End Sub