Creating new sheets from template sheet plugging data into new sheets with particular criterias

skydd

New Member
Joined
Apr 25, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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
 

Attachments

  • 1714043387746.png
    1714043387746.png
    108.6 KB · Views: 6

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,956
Members
449,200
Latest member
indiansth

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