Siddhu11011
Board Regular
- Joined
- Jun 22, 2022
- Messages
- 56
- Office Version
- 365
- Platform
- Windows
Macro1 creates multiple sheets and the same work book and Macro2 feeds the data in sheets created by Macro1
Macro1 depends on data in columns A to P of master_db sheet and new sheets creation is based on unique product name available in Column B of master_db sheet.
Macro2 looks into same unique product name which was created in Macro1. We have multiple sheets available which is created in macro1, now macro 2 pick one by one product name and fetch the data from "comparison" sheet. That sheet has data from column A to E.
Sub Macro1()
Dim x As Range
Dim Rng As Range
Dim last As Long
Dim sht As String
sht = "master_db"
last = Sheets(sht).Range("A1:P" & last)
Sheets(sht).Range("B1:B" & last). AdvancedFilter Action:=XlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
For Each x In Range([AA2], Cells(Rows.Count, "AA").End(xlUp))
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
Next x
End Sub
Sub Macro2()
Dim rngCell As Range
Dim rngWork As Range
Dim wsPivot As Worksheet
Set wsPivot = ThisWorkbook.Worksheets("Pivot")
With wsPivot
Set rngWork = .Range("A1:E" & .Cell(.Rows. Count, "A").End(xlUp).Row)
If Not rngWork Is Nothing Then
For Each rngCell In .Range([AA2], .Cells(Rows.Count, "AA").End(xlUp))
With rngWork
.AutoFilter
.AutoFilter Feild:=1, Criterial:=rngCell.Value
.SpecialCells(xlCellTypeVisible).Copy Worksheets(rngCell.Value).Range("A")
End With
End Sub
Requirement:
I want macro to create new sheets in the new work book (instead of the same workbook) and pull the data from comparison sheet in the new workbook- in respective sheet
Is that a possible?
Macro1 depends on data in columns A to P of master_db sheet and new sheets creation is based on unique product name available in Column B of master_db sheet.
Macro2 looks into same unique product name which was created in Macro1. We have multiple sheets available which is created in macro1, now macro 2 pick one by one product name and fetch the data from "comparison" sheet. That sheet has data from column A to E.
Sub Macro1()
Dim x As Range
Dim Rng As Range
Dim last As Long
Dim sht As String
sht = "master_db"
last = Sheets(sht).Range("A1:P" & last)
Sheets(sht).Range("B1:B" & last). AdvancedFilter Action:=XlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
For Each x In Range([AA2], Cells(Rows.Count, "AA").End(xlUp))
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
Next x
End Sub
Sub Macro2()
Dim rngCell As Range
Dim rngWork As Range
Dim wsPivot As Worksheet
Set wsPivot = ThisWorkbook.Worksheets("Pivot")
With wsPivot
Set rngWork = .Range("A1:E" & .Cell(.Rows. Count, "A").End(xlUp).Row)
If Not rngWork Is Nothing Then
For Each rngCell In .Range([AA2], .Cells(Rows.Count, "AA").End(xlUp))
With rngWork
.AutoFilter
.AutoFilter Feild:=1, Criterial:=rngCell.Value
.SpecialCells(xlCellTypeVisible).Copy Worksheets(rngCell.Value).Range("A")
End With
End Sub
Requirement:
I want macro to create new sheets in the new work book (instead of the same workbook) and pull the data from comparison sheet in the new workbook- in respective sheet
Is that a possible?