Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Macro to create seperate sheets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony - 10 Dec 2007 08:12 GMT
I have one worksheet containing a list of all sales from all salespeople,
salesperson's name is in column B with other details in further columns.

Eg  Master sheet
Col B               Col C         Col D        Col E  
Salesperson     Prodcuct    Amount     Discount
Simon             XYZ           500           50
Simon             ABC           600           50
Simon             123            400          10
Olivia              ABC            650          50
Olivia              DEF            660          60

I would like to break out Simons details onto one sheet and Olivias onto
another (seperate sheets already exist and with formulas in certain cells) so
that they appear on the new sheet in say range starting in C10 down.
The number of times that Simon and Olivia would appear would vary every time
the master sheet is created.

Any help would be much appreciated.

Thanks
Bob Phillips - 10 Dec 2007 09:29 GMT
Public Sub ProcessData()
Const TEST_COLUMN As String = "B"    '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim StartRow As Long
Dim sh As Worksheet

   With ActiveSheet

       LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
       For i = 2 To LastRow + 1
           If .Cells(i, TEST_COLUMN).Value <> .Cells(i - 1,
TEST_COLUMN).Value Then
               If i > 2 Then
                   .Cells(StartRow, TEST_COLUMN).Resize(i - StartRow,
4).Copy sh.Range("C11")
               End If
               If i <= LastRow Then
                   Set sh = Worksheets(.Cells(i, TEST_COLUMN).Value)
                   sh.Cells.ClearContents
                   .Range("B1:E1").Copy sh.Range("C10")
                   StartRow = i
               End If
           End If
       Next i

   End With

End Sub

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

>I have one worksheet containing a list of all sales from all salespeople,
> salesperson's name is in column B with other details in further columns.
[quoted text clipped - 19 lines]
>
> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.