LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JonR
 
Posts: n/a
Default Sorting into different worksheets from a unique value

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to maintain hyperlink between worksheets after sorting Gallatin Excel Worksheet Functions 2 May 16th 06 09:36 PM
how do i find unique avg buy prices in multiple group of buys/sell John Robbins Excel Worksheet Functions 1 May 4th 06 06:44 PM
sorting worksheets based on a cell value Patrick Excel Worksheet Functions 3 May 2nd 06 06:49 PM
Combining worksheets on a unique key column Ben Excel Worksheet Functions 0 April 20th 06 01:19 AM
Excel needs to have the ability to insert "SUB" worksheets KFEagle Excel Worksheet Functions 2 July 27th 05 08:13 PM


All times are GMT +1. The time now is 09:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"