Help With Macro to Create Sheets From Master

gaspower

Board Regular
Joined
Jun 10, 2005
Messages
55
Hello,
I have a master sheet(sheet1),
main.jpg


I need to be able to create three sheets from the master, 811, 811B, 811E. Does not mater if sheets are called the 811's, can just be sheet2, sheet3 etc. I can rename later. But what I would like the macro to do, is on each sheet created, have the corresponding products in the sheet denoted by the "X".

Example:
811
811.jpg


811B
811.jpg


811E
811E.jpg


Thanks JR
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Give this a try:
Code:
Option Explicit

Sub ParseData()
Dim ws As Worksheet, sName As String
Dim Col As Long, LR As Long, LC As Long
Application.ScreenUpdating = False

With Sheets("Master")
    LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
    .AutoFilterMode = False
    .Rows(1).AutoFilter
    For Col = 3 To LC
        sName = .Cells(1, Col)
        If Not Evaluate("ISREF('" & sName & "'!A1)") Then
            Sheets.Add(After:=Sheets(Sheets.Count)).Name = sName
        Else
            Sheets(sName).UsedRange.Clear
        End If
        .Rows(1).AutoFilter Field:=Col, Criteria:="*"
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        If LR > 1 Then .Range("A1:B" & LR).Copy Sheets(sName).Range("A1")
        .Rows(1).AutoFilter Field:=Col
    Next Col
    .AutofilterMode = False
    .Activate
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello,

thank you very much for the reply. I tried the macro, but I get an visual basic error 400.

JR
 
Upvote 0
Sorry, my bad, little typo. I went ahead and added a formatting tweak, too.
Rich (BB code):
Option Explicit

Sub ParseData()
Dim ws As Worksheet, sName As String
Dim Col As Long, LR As Long, LC As Long
Application.ScreenUpdating = False

With Sheets("Master")
    LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
    .AutoFilterMode = False
    .Rows(1).AutoFilter
    For Col = 3 To LC
        sName = .Cells(1, Col)
        If Not Evaluate("ISREF('" & sName & "'!A1)") Then
            Sheets.Add(After:=Sheets(Sheets.Count)).Name = sName
        Else
            Sheets(sName).UsedRange.Clear
        End If
        .Rows(1).AutoFilter Field:=Col, Criteria1:="*"
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        If LR > 1 Then
            .Range("A1:B" & LR).Copy Sheets(sName).Range("A1")
            Sheets(sName).Columns.AutoFit
        End If
        .Rows(1).AutoFilter Field:=Col
    Next Col
    .AutoFilterMode = False
    .Activate
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello,

I really want to thank you for helping me. I think we are very close. Sheet 811 and 811B are created fine. Sheet 811E does not get created correctly. For example 1311 ad 1315 are added to the list when there is no "X" in the field of the master.

Thanks JR
 
Upvote 0
This is what I get when I run it:

Excel Workbook
AB
1Part #Product List
21312Sample Product 2
31321Sample Product 4
41337Sample Product 5
51383Sample Product 6
61394Sample Product 7
71606Sample Product 10
811E


I'm going to "guess" that the cells in column 811E aren't really "blank" where they appear to be. Perhaps change that to:
Rich (BB code):
.Rows(1).AutoFilter Field:=Col, Criteria1:="x"
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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