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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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
Back
Top