Hello!
I'm trying to create a MACRO that uses VBA to create sheets and plug information into those sheets given a particular criteria.
Essentially, I've created a template worksheet and I've coded the VBA to create a new worksheet out of that template for each unique value in column "D" of my data input. It then copies that unique value into cell A2 on the new sheet and titles the new sheet with the unique value of the original cell.
Column D in my data set is individual names. Column E is a course code that that particular name has to complete.
My current coding takes that employees name and creates a new worksheet titled with the employees name and also inserts the employees name onto the new sheet in cell A2.
I need it to then pull all of the values from cell E that have the employee's name from cell A2 to range A10:A.
I cannot get it to pull the data from column E to the new worksheet. I dont know how to filter it out and only pull the data that matches cell A2.
Sub CreateSheetsFromColumn()
Dim ws As Worksheet
Dim r As Range
Dim sheetName As String
Dim sheetExists As Boolean
' Set reference to the worksheet where the data is stored
Set ws = ThisWorkbook.sheets("INPUT")
' Loop through each cell in column A (starting from A2)
For Each r In ws.Range("D2:D" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row)
sheetName = r.Value
sheetExists = False
' Check if the sheet already exists
For Each Sheet In Worksheets
If Sheet.Name = sheetName Then
sheetExists = True
Exit For
End If
Next Sheet
' If the sheet does not exist, create it
If Not sheetExists And sheetName <> "" Then
sheets.Add(After:=sheets(sheets.Count)).Name = sheetName
sheets("Template").Select
Cells.Select
Selection.Copy
sheets(sheetName).Select
Cells.Select
ActiveSheet.Paste
ActiveSheet.Range("A2").Value = sheetName
End If
Next r
End Sub
I'm trying to create a MACRO that uses VBA to create sheets and plug information into those sheets given a particular criteria.
Essentially, I've created a template worksheet and I've coded the VBA to create a new worksheet out of that template for each unique value in column "D" of my data input. It then copies that unique value into cell A2 on the new sheet and titles the new sheet with the unique value of the original cell.
Column D in my data set is individual names. Column E is a course code that that particular name has to complete.
My current coding takes that employees name and creates a new worksheet titled with the employees name and also inserts the employees name onto the new sheet in cell A2.
I need it to then pull all of the values from cell E that have the employee's name from cell A2 to range A10:A.
I cannot get it to pull the data from column E to the new worksheet. I dont know how to filter it out and only pull the data that matches cell A2.
Sub CreateSheetsFromColumn()
Dim ws As Worksheet
Dim r As Range
Dim sheetName As String
Dim sheetExists As Boolean
' Set reference to the worksheet where the data is stored
Set ws = ThisWorkbook.sheets("INPUT")
' Loop through each cell in column A (starting from A2)
For Each r In ws.Range("D2:D" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row)
sheetName = r.Value
sheetExists = False
' Check if the sheet already exists
For Each Sheet In Worksheets
If Sheet.Name = sheetName Then
sheetExists = True
Exit For
End If
Next Sheet
' If the sheet does not exist, create it
If Not sheetExists And sheetName <> "" Then
sheets.Add(After:=sheets(sheets.Count)).Name = sheetName
sheets("Template").Select
Cells.Select
Selection.Copy
sheets(sheetName).Select
Cells.Select
ActiveSheet.Paste
ActiveSheet.Range("A2").Value = sheetName
End If
Next r
End Sub