Hello,
I'm trying to make a VBA code that allow me to create new sheets with names corresponding to a values in a range, and then fill them.
So, I have one sheet named "Team Statistics", with a table. With the first column ("A3:A14") I want to generate new sheets and rename them with each Cells value of the range ("A3:A14"). (I got a code for this part).
Then, For each sheet I want to copy from the sheet "Team Statistics" the line corresponding to the sheet name. (E.g. if the name of my first sheet is "AAA" --> Go to sheet "Team Statistics", search in column ("A3:A14") for value "AAA", copy the corresponding line ("AAA") and past in the sheet "AAA".
This is the code I already write, could you please help me to finish the code "FillEachSheet" ?
Thank you
I'm trying to make a VBA code that allow me to create new sheets with names corresponding to a values in a range, and then fill them.
So, I have one sheet named "Team Statistics", with a table. With the first column ("A3:A14") I want to generate new sheets and rename them with each Cells value of the range ("A3:A14"). (I got a code for this part).
Then, For each sheet I want to copy from the sheet "Team Statistics" the line corresponding to the sheet name. (E.g. if the name of my first sheet is "AAA" --> Go to sheet "Team Statistics", search in column ("A3:A14") for value "AAA", copy the corresponding line ("AAA") and past in the sheet "AAA".
This is the code I already write, could you please help me to finish the code "FillEachSheet" ?
Code:
Sub CreateSheetsFromAList()
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Team Statistics").Range("A3")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
Sheets.Add After:=Sheets(Sheets.Count) 'creates a new worksheet
Sheets(Sheets.Count).Name = MyCell.Value ' renames the new worksheet
Next MyCell
Worksheets("Grand Total").Delete
End Sub
Sub FillEachSheet()
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Team Statistics").Range("A3")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
If Sheets(Sheets.Count).Name = MyCell.Value Then
...
Next MyCell
End Sub
Thank you
Last edited: