Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I am trying to create vba code to sort multiple sheets by clicking on a
command button. I got it to sort the first page correctly, (the page the button is on), but I'm having trouble getting it to sort other pages. I get this error: "Method 'Range' of object '_Worksheet' failed." On each sheet, I have three columns with headers: first name (columnA), last name(columnB), and number (columnC). Here is the code I have so far. I have one sub to sort the sheets alphabetically, and one to sort by number: Option Explicit Private Sub cmdSortAlpha_Click() Worksheets("Sheet1").Select Worksheets("Sheet1").Range("A2:C50").Sort _ Key1:=Range("A2:A50"), _ Order1:=xlAscending, _ Key2:=Range("B2:B50"), _ Order2:=xlAscending, _ Header:=xlNo Worksheets("Sheet2").Select Worksheets("Sheet2").Range("A2:C50").Sort _ Key1:=Range("A2:A50"), _ Order1:=xlAscending, _ Key2:=Range("B2:B50"), _ Order2:=xlAscending, _ Header:=xlNo End Sub Private Sub cmdSortNumber_Click() Worksheets("Sheet1").Select Worksheets("Sheet1").Range("A2:C50").Sort _ Key1:=Range("C2:C50"), _ Order1:=xlAscending, _ Header:=xlNo Worksheets("Sheet2").Select Worksheets("Sheet2").Range("A2:C50").Sort _ Key1:=Range("C2:C50"), _ Order1:=xlAscending, _ Header:=xlNo End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
sorting sheets | New Users to Excel | |||
sorting protected sheets | Excel Worksheet Functions | |||
Multiple Sheets (Need to create 500 individual sheets in one workbook, pulling DATA | Excel Worksheet Functions | |||
Sorting sheets | Excel Discussion (Misc queries) | |||
Sorting Data to Different Sheets | Excel Worksheet Functions |