Why does my vba code not run

December 1, 2019 at 00:30:52
Specs: Windows 10

Hi I have entered the code as listed below in the module but when I click the run button I get the
window to enter the Macro name.All other buttons are not highlighted. Please help

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
End If
End Sub

See More: Why does my vba code not run

Reply ↓  Report •

December 1, 2019 at 14:26:26
It won't run normally because it's declared as Private. You need to either call it from another sub, or else remove the Private keyword. (Also, to be called properly, it needs to be in a worksheet's object, not a module. In that case, Private is correct, and it will be called automagically.)

Reply ↓  Report •

December 1, 2019 at 18:29:10
Thank you Willy. I have changed the code as you suggested and ,,,,,magic!
Thanks again

Reply ↓  Report •
Related Solutions

Ask Question