Home |
Search |
Today's Posts |
#13
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Maria,
What threw the code off is you had a "Green" in the criteria column. The code didn't find anything to do with it in the "Select Case" statement, so it stopped. I've fixed it in the sample sheet, and put in another two worksheets labeled "Green" and "Other" so the greens will sort ot ht eGreen sheet, and everything else (Purple, Black, Orange) will go onto the "Other" sheet. I've e-mailed the sheet back to you, but will post the code here also for others who might be following this thread. I also put a comand button on your master sheet, so all you have to do is click the button to run the sort macro. Sub Sort() 'This simple macro will sort data onto different worksheets based on criteria in 'the cell in column B Dim x, z On Error Resume Next 'if something goes wrong, it will skip to the next line Worksheets("Master").Activate 'Rename the sheet to suit. Be sure to leave the quotation marks Application.ScreenUpdating = False 'Turns off the screen updating. This makes the code run faster and the flashing 'sheets won't drive you bonkers. Stepping through the code with F8 ignores this command 'so you'll still be able to see it work if you step through Cells(1, 1).Activate x = 3 Do Until Cells(x, 1).Value = "" ' This steps through the first column until it hits a blank. X is the row number 'modify this Range statement to gather the entire row of data 'Cell references in VBA are Cells(Row,Column) 'be careful, because it's easy to get it backward Range(Cells(x, 1), Cells(x, 52)).Copy 'Select the proper worksheet based on color criteria 'Likewise, you will need to ensure you are referring to the cell 'that contains your sort criteria, and also change the Case statement accordingly Select Case Cells(x, 32).Value Case "Red" Worksheets("Red").Activate Case "Yellow" Worksheets("Yellow").Activate Case "Blue" Worksheets("Blue").Activate Case "Green" Worksheets("Green").Activate Case Else Worksheets("Other").Activate End Select Cells(3, 1).Activate 'this IF function (and those like it) finds the next open row If Cells(3, 1).Value = "" Then z = 3 ElseIf Cells(4, 1).Value = "" Then z = 4 Else z = ActiveCell.End(xlDown).Row + 1 End If Cells(z, 1).PasteSpecial 'Pastes your range into the appropriate open row Worksheets("Master").Activate x = x + 1 Loop Application.ScreenUpdating = True 'turns screen updating back on End Sub -- HTH JonR "Maria" wrote: I have tried emailing the spreadsheet to you at , but the email will not go through to that address. Please reply to my email address so I can send it to you. Thanks. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how to maintain hyperlink between worksheets after sorting | Excel Worksheet Functions | |||
how do i find unique avg buy prices in multiple group of buys/sell | Excel Worksheet Functions | |||
sorting worksheets based on a cell value | Excel Worksheet Functions | |||
Combining worksheets on a unique key column | Excel Worksheet Functions | |||
Excel needs to have the ability to insert "SUB" worksheets | Excel Worksheet Functions |