Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
In the same workbook I have two worksheets: Worksheet 1 Range("D5:D55") is the range to sort Worksheet 2 Range("B4:C103"). Worksheet 1 - data Column D 0125 0502 1250 2500 Worksheet 2 - data Column B Column C 0125 Name 1 0502 Name 2 1250 Name 3 2500 Name 4 How can I use a macro to use worksheet 1 range to sort worksheet 2 range as described above? Thank you for your help, jfcby |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
Thank you for your help! Problem has been solved with the help of a co-worker and the macros below: [EXTRA INFO: If you want to run a macro to create a Custom List follow these directions .......Go To - TOOLS MACROS RECORD NEW MACRO OK 1. In a range of cells, enter the values you want to sort by, in the order you want them, from top to bottom. For example: DATA High Medium Low 2. Select the range. 3. On the TOOLS menu, click OPTIONS, and then click the CUSTOMS LISTS tab. 4. Click IMPORT, and then click OK. 5. Select a cell in the range you want to sort. 6. On the DATA menu, click SORT. 7. In the SORT BY box, click the column you to sort. 8. Click OPTIONS. 9. Under FIRST KEY SORT ORDER, click the list you created. For example, click HIGH, MEDIUM, LOW. 10. Click OK. 11. Select any other sort options you want, and then click OK. NOTE: You can't use a custom sort order in a THEN BY box. The custom sort order applies only to the column specified in the SORT BY box. To sort multiple columns by using a custom sort order, sort by each column separately. For example, to sort by columns A and B, in the order, first sort by column B, and then specify the custom sort by using the SORT OPTIONS dialog box. Next, sort the range by column A. .......click STOP RECORDING button <<] Macro 1: SortRangeExampleB - Sorts Range from an Array Range same Worksheet '-- Sub SortRangeExampleB() 'Sorts Range from an Array Range same Worksheet Dim myArr As Variant Dim myListNumber As Long '-- myArr = Range("H1:H11") Application.AddCustomList ListArray:=myArr myListNumber = Application.GetCustomListNum(myArr) '-- Range("G1:G11").Select '-- Selection.Sort Key1:=Range("G1"), Order1:=xlAscending, _ Header:=xlGuess, OrderCustom:=myListNumber + 1 '-- Application.DeleteCustomList myListNumber End Sub '<<--<< Macro 2: SortRangeExampleC - Sorts Range from an Array Range separate Worksheets '-- Sub SortRangeExampleC() 'Sorts Range from an Array Range separate Worksheets Dim myArr As Variant Dim myListNumber As Long '-- myArr = Worksheets("MACROS").Range("H1:H11") 'change worksheet & range Application.AddCustomList ListArray:=myArr myListNumber = Application.GetCustomListNum(myArr) '-- Worksheets("Activate Macro Buttons").Select 'change worksheet Worksheets("Activate Macro Buttons").Range("G1:G11").Select 'change worksheet & range '-- change worksheet & range Selection.Sort Key1:=Worksheets("Activate Macro Buttons").Range("G1"), Order1:=xlAscending, _ Header:=xlGuess, OrderCustom:=myListNumber + 1 '-- Application.DeleteCustomList myListNumber End Sub <<-- Thank you for your help, jfcby |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Why can't I repeat a sort on another range of a worksheet? | Excel Worksheet Functions | |||
Loop through Row Range, Excel 2000, 2003 | Excel Programming | |||
Worksheet Range Question - Excel 2003 | Excel Programming | |||
worksheet in excel 2000 different than 2003 | Excel Discussion (Misc queries) | |||
How do I sort a range of cells via a worksheet function | Excel Worksheet Functions |