VB sort grabs header

ekinzie

New Member
Joined
Jan 25, 2005
Messages
5
I have a very simple spreadsheet using Excel 2002 SP3. I am using a script I found on this site and a button to sort data by a particular field. I don't have much knowledge of VB. Heres the script:

Private Sub Worksheet_Activate()
On Error Resume Next
Application.EnableEvents = False
Me.UsedRange.Sort _
Key1:=[A1], Order1:=xlAscending, header:=xlYes, Orientation:=xlSortColumns
Application.EnableEvents = True
On Error GoTo 0
End Sub

Basically, everything works ok but the script, it puts the data on top of the header, which occupies row 2. The data starts in row 3 while row 1 contains the worksheet name. Please help!

Ek
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

martinee

Well-known Member
Joined
Nov 4, 2003
Messages
960
Instead of Me.UsedRange.Sort....
try:
Me.Range("A3:F" & Range("F65536").End(xlUp).Row)

In this case, F is your last column of data; change to suit. HTH.
 

ekinzie

New Member
Joined
Jan 25, 2005
Messages
5
Thanks for your help.

That gives me an error but I managed to find a way around it. I basically moved the worksheet name into the document header which allowed me to move the data header up to row 1.

Now on to my next problem!

Thanks again
 

Forum statistics

Threads
1,147,622
Messages
5,742,199
Members
423,711
Latest member
luisfreitas

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top