I have multiple sheets, the main sheet Input has my raw data, I have another sheet with my filtered data. I want to create a new sheet for each cell value in Sheet2 column A and have it populate the sheet with the rows matching my cell value in Sheet1.
My code below creates the sheets with the cell values but only populates the first sheet.
Sub CreateSheetForValue()
Dim d As Range
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Dim Condition As Worksheet
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Condition = ActiveWorkbook.Worksheets("Sheet2")
j = 2 'This will start copying data to Target sheet at row 2
For Each d In Condition.Range("A2:A21") 'specifiy condition
'create wroksheet for each value in condition
Set Target = Sheets.Add(after:=ActiveSheet)
'ActiveSheet.Name = d.Value
Target.Name = d.Value
Sheets("Input").Range("A1:G1").Copy Target.Range("A1")
For Each c In Source.Range("E2:E1893")
If Target.Name = d.Value And c.Value = d.Value Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
Next d
End Sub