VBA Sort Button

jj72uk

Registered User.
Local time
Today, 13:10
Joined
May 19, 2009
Messages
65
Ok, so I have a workbook with 4 sheets, on one sheet I want to have a button that will sort data on a differing sheet.

I wrote some VBA code and it didn't work, so I went back to basics and used the macro record and the code were virtually like for like, I took the code from the recorded macro and put it into the VBA code for my button but it still kicks up a fuss.

Can anyone point me in the right direction

Code:
Private Sub CommandButton1_Click()
    Sheets("Team DB").Select
    ActiveWindow.SmallScroll Down:=-64
    Range("A3:D94").Select
    Selection.Sort Key1:=Range("D3"), Order1:=xlDescending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

This is the code from the macro, my orginal code was identical apart from the the 'ActiveWindow.SmallScroll Down......'

When it comes to the debug it highlights:

Range("A3:94").Select


Help please!!
 
Hi,

Code:
Private Sub CommandButton1_Click()
With Sheets("Team DB")
    .Range("A3:[COLOR="Red"][B]D[/B][/COLOR]94").Sort _
        Key1:=.Range("D3"), _
        Order1:=xlDescending, _
        Header:=xlGuess, _
        OrderCustom:=1, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom
End With
End Sub
Ciao,
Holger
 

Users who are viewing this thread

Back
Top Bottom