VBAveenker
Technical User
Banging my head against a wall here. I'm new to the VBA world, so trying to get something simple done here.
Created a macro button to automatically insert a column with autofill on certain cells. However, I don't want users selecting any cell to insert this column (especially because undo is wiped out). To prevent this from happening, I have tried to create a macro that when played, if a cell in the appropiate range is not selected, a message box appears telling them which cells to select. At that point, the macro should prevent them from entering the new column in the wrong cell (am I confusing anyone yet?) However, if a cell in the appropiate range is selected, the macro is allowed to play.
Here is what I have so far - you can see that if the user chooses "yes", they could potentially be placing the column in the wrong place.
Sub Insert_Column()
'
' Insert_Column Macro
' Macro recorded 5/23/2007 by
'
'
returnvalue = MsgBox("Have you selected the location of your column?" & Chr(13) & _
"(Incorrect placement of column could result in unreversable changes)", 52, "Warning")
If returnvalue = 6 Then
Selection.EntireColumn.Insert
Set selection1 = ActiveSheet.Range("c12")
Set selection2 = ActiveSheet.Range("c12:ah12")
'Autofill
selection1.AutoFill Destination:=selection2
Set selection3 = ActiveSheet.Range("c22")
Set selection4 = ActiveSheet.Range("c22:ah22")
selection3.AutoFill Destination:=selection4
Set selection5 = ActiveSheet.Range("c23")
Set selection6 = ActiveSheet.Range("c23:ah23")
selection5.AutoFill Destination:=selection6
Set selection7 = ActiveSheet.Range("c27")
Set selection8 = ActiveSheet.Range("c27:ah27")
selection7.AutoFill Destination:=selection8
Set selection9 = ActiveSheet.Range("c28")
Set selection10 = ActiveSheet.Range("c28:ah28")
selection9.AutoFill Destination:=selection10
Set selection11 = ActiveSheet.Range("c29")
Set selection12 = ActiveSheet.Range("c29:ah29")
selection11.AutoFill Destination:=selection12
End If
End Sub
Any input is appreciated. Thanks!
-veenker
Created a macro button to automatically insert a column with autofill on certain cells. However, I don't want users selecting any cell to insert this column (especially because undo is wiped out). To prevent this from happening, I have tried to create a macro that when played, if a cell in the appropiate range is not selected, a message box appears telling them which cells to select. At that point, the macro should prevent them from entering the new column in the wrong cell (am I confusing anyone yet?) However, if a cell in the appropiate range is selected, the macro is allowed to play.
Here is what I have so far - you can see that if the user chooses "yes", they could potentially be placing the column in the wrong place.
Sub Insert_Column()
'
' Insert_Column Macro
' Macro recorded 5/23/2007 by
'
'
returnvalue = MsgBox("Have you selected the location of your column?" & Chr(13) & _
"(Incorrect placement of column could result in unreversable changes)", 52, "Warning")
If returnvalue = 6 Then
Selection.EntireColumn.Insert
Set selection1 = ActiveSheet.Range("c12")
Set selection2 = ActiveSheet.Range("c12:ah12")
'Autofill
selection1.AutoFill Destination:=selection2
Set selection3 = ActiveSheet.Range("c22")
Set selection4 = ActiveSheet.Range("c22:ah22")
selection3.AutoFill Destination:=selection4
Set selection5 = ActiveSheet.Range("c23")
Set selection6 = ActiveSheet.Range("c23:ah23")
selection5.AutoFill Destination:=selection6
Set selection7 = ActiveSheet.Range("c27")
Set selection8 = ActiveSheet.Range("c27:ah27")
selection7.AutoFill Destination:=selection8
Set selection9 = ActiveSheet.Range("c28")
Set selection10 = ActiveSheet.Range("c28:ah28")
selection9.AutoFill Destination:=selection10
Set selection11 = ActiveSheet.Range("c29")
Set selection12 = ActiveSheet.Range("c29:ah29")
selection11.AutoFill Destination:=selection12
End If
End Sub
Any input is appreciated. Thanks!
-veenker