Hi guys,
After reading a lot around here and many beginner fails, I give up and kindly ask for your help with the below.
I need a macro to add specific values (let's say d/e/f) on the 2nd row after the last used column, in specific colors.
Should be something like this, but something is definitely wrong.
Could you pls pls pls help?
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = ActiveSheet
With ws
LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Columns(LastCol + 1).EntireColumn.Insert
.Cells(2, LastCol + 1).Value = "d"
End with
.Cells(2, LastCol + 1).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
.Columns(LastCol + 2).EntireColumn.Insert
.Cells(2, LastCol + 2).Value = "e"
Cells(2, Columns.Count).End(xlToLeft).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
.Columns(LastCol + 3).EntireColumn.Insert
.Cells(2, LastCol + 3).Value = "f"
Cells(2, Columns.Count).End(xlToLeft).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
End Sub
After reading a lot around here and many beginner fails, I give up and kindly ask for your help with the below.
I need a macro to add specific values (let's say d/e/f) on the 2nd row after the last used column, in specific colors.
Should be something like this, but something is definitely wrong.
Could you pls pls pls help?
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Set ws = ActiveSheet
With ws
LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Columns(LastCol + 1).EntireColumn.Insert
.Cells(2, LastCol + 1).Value = "d"
End with
.Cells(2, LastCol + 1).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
.Columns(LastCol + 2).EntireColumn.Insert
.Cells(2, LastCol + 2).Value = "e"
Cells(2, Columns.Count).End(xlToLeft).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
.Columns(LastCol + 3).EntireColumn.Insert
.Cells(2, LastCol + 3).Value = "f"
Cells(2, Columns.Count).End(xlToLeft).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
End Sub