Copy all Rows with a cell of value 'x' to a worksheet named 'x'

sauce1979

New Member
Joined
Aug 4, 2011
Messages
9
I am a sql developer who has some experience with Excel but none using Macros etc. I export a data set into Excel from SQL Server. For futher analysis I need to split that dataset such that rows with a particular value end up in a particular worksheet with the name of that value.

As an example I have some data as follows:

Code:
[B]D_AC        D_RU          D_SBU     f00[/B]
501          207         90001      34
502          208         90021      54
501          208         90001      44
501          208         90312      84
501          209         90001      54
501          209         90211      54
501          210         90021      64
501          210         90001      54
In the example above, I would like to send all rows containing D_RU 207 to a worksheet called 207, _RU 208 to a worksheet called 208, _RU 209 to a worksheet called 209, etc

From what I have read I would need to use a Macro but I am not precisely sure how I would do that. I could easily create this in SQL server but the version I am using at work does not have the functionality needed. Any help you could provide would be very much appreciated
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
and this idea for code may be will help you
assume your main sheet name is Data
Code:
Sub sauce1979()
Dim LR As Long, c As Range, ws As Worksheet
Set ws = Sheets("DATA")
LR = Range("a" & Rows.Count).End(xlUp).Row
ws.Range("B1:B" & LR).AdvancedFilter xlFilterCopy, , [K1], True
For Each c In ws.Range("k2:k" & Range("K" & Rows.Count).End(xlUp).Row)
    Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = c.Value
    With ws.Range("a1:D" & LR)
        .AutoFilter 2, c.Value
        .Copy ActiveSheet.Range("a1")
        .AutoFilter
    End With
Next c
ws.Range("k1").EntireColumn.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top