I am trying to get a 'macro' to start with Cell D1 and if it contains data, insert a column next to it and set its formula to the afore mentioned cell and concatenate " Update" to it.
My problem seems to be with the line of code
lngColumn = ActiveCell.Column
Below is my procedure. I understand that it doesn't work because it is returning the column of the active range instead of the column's postion on the entire sheet. I just don't know the Excel object model well enough to fix it.
Your help is most appreciated.
Sub Example
Dim lngColumn As Long
Application.WindowState = xlMinimized
ActiveSheet.Range("D1").Select
While IsNull(ActiveCell.Formula) = False
lngColumn = ActiveCell.Column
ActiveSheet.Columns(lngColumn + 1).Select
Selection.Insert Shift:=xlToRight
ActiveSheet.Range(lngColumn + 1 & ":1").Select
ActiveCell.FormulaR1C1 = "=RC[-1] & "" Update"""
ActiveSheet.Columns(ActiveCell.Column).EntireColumn.AutoFit
ActiveSheet.Columns(ActiveCell.Column).Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Range(lngColumn + 2 & ":1").Select
Wend
Cells.Select
Cells.EntireColumn.AutoFit
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
My problem seems to be with the line of code
lngColumn = ActiveCell.Column
Below is my procedure. I understand that it doesn't work because it is returning the column of the active range instead of the column's postion on the entire sheet. I just don't know the Excel object model well enough to fix it.
Your help is most appreciated.
Sub Example
Dim lngColumn As Long
Application.WindowState = xlMinimized
ActiveSheet.Range("D1").Select
While IsNull(ActiveCell.Formula) = False
lngColumn = ActiveCell.Column
ActiveSheet.Columns(lngColumn + 1).Select
Selection.Insert Shift:=xlToRight
ActiveSheet.Range(lngColumn + 1 & ":1").Select
ActiveCell.FormulaR1C1 = "=RC[-1] & "" Update"""
ActiveSheet.Columns(ActiveCell.Column).EntireColumn.AutoFit
ActiveSheet.Columns(ActiveCell.Column).Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Range(lngColumn + 2 & ":1").Select
Wend
Cells.Select
Cells.EntireColumn.AutoFit
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub