Forum Discussion

calof1's avatar
calof1
Iron Contributor
Jan 02, 2020
Solved

Help automatically sorting data in excel

Hi,

 

I have data which needs to be sorted by "Security Type" or column E on the Valuation tabs. I have seen a macro online and tried to implement, however it doesn't seem to work for my spreadsheet.

 

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        Range("A1").Sort Key1:=Range("A2"), _
          Order1:=xlAscending, Header:=xlYes, _
          OrderCustom:=1, MatchCase:=False, _
          Orientation:=xlTopToBottom
    End If
End Sub

 Can someone please advise what i need to change to get it to work for my spreadsheet.

 

Thanks,

  • calof1 You just need to copy the code you have created from the Module 1 into the code window for the sheet. The code runs off the Worksheet change event so it needs to be in the sheet to operate.

     

    In the Visual Basic Editor, just go to Module 1 and Copy. Then double click on Sheet 4 or whatever sheets you want it to run in and paste it into there. It will work fine.

3 Replies

  • calof1 You just need to copy the code you have created from the Module 1 into the code window for the sheet. The code runs off the Worksheet change event so it needs to be in the sheet to operate.

     

    In the Visual Basic Editor, just go to Module 1 and Copy. Then double click on Sheet 4 or whatever sheets you want it to run in and paste it into there. It will work fine.

Resources