Create & name worksheets from a list and copy data
Solved/Closed
RachJol
Posts
3
Registration date
Tuesday 4 October 2016
Status
Member
Last seen
4 October 2016
-
4 Oct 2016 à 11:10
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 6 Oct 2016 à 11:07
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 6 Oct 2016 à 11:07
Related:
- Creating multiple worksheets from a template and a list of names
- How to split excel sheet into multiple worksheets - Guide
- "You can make a private videos list and share them only with your favorite friends!" - Guide
- Counter strike 1.6 cheats list - Guide
- Epic games free games list - Guide
- Names for whatsapp profile - WhatsApp Forum
2 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
4 Oct 2016 à 11:21
4 Oct 2016 à 11:21
Hi RachJol,
You mean like this?:
Best regards,
Trowa
Monday, Tuesday and Thursday are usually the days I'll respond. Bear this in mind when awaiting a reply.
You mean like this?:
Sub CreateSheetsFromAList()
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Data Entry").Range("A2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
Sheets("Template").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = MyCell.Value ' renames the new worksheet
Range("F3").Value = MyCell.Value
Range("F4").Value = MyCell.Offset(0, 1).Value
Next MyCell
End Sub
Best regards,
Trowa
Monday, Tuesday and Thursday are usually the days I'll respond. Bear this in mind when awaiting a reply.
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
6 Oct 2016 à 11:07
6 Oct 2016 à 11:07
Hi Rachael,
To check if a sheet already exist you can use this custom code:
Place this code after the End Sub line and then use this line in your code:
Best regards,
Trowa
To check if a sheet already exist you can use this custom code:
Function SheetExists(SheetName As String) As Boolean SheetExists = False On Error GoTo NoSuchSheet If Len(Sheets(SheetName).Name) > 0 Then SheetExists = True Exit Function End If NoSuchSheet: End Function
Place this code after the End Sub line and then use this line in your code:
If Not SheetExists(“MySheetName”) Then
Best regards,
Trowa
4 Oct 2016 à 11:53
Thanks so much, that works brilliantly. The only thing is when it reaches the end of the list it tries to copy 'Template' again and comes up with a Run-time error 1004 "That name is already taken. Try a different one".
If you can suggest anything that would be very helpful.
Thanks
Rachael
4 Oct 2016 à 12:01
That would suggest a duplicate entry in your Room name list.
I downloaded your file, run the code and no error occured.
What did you change?
Best regards,
Trowa
4 Oct 2016 à 12:08
Sub CreateSheetsFromAList() Dim MyCell, MyRange As Range Set MyRange = Sheets("Data Entry").Range("A2") Set MyRange = Range(MyRange, MyRange.End(xlDown)) Sheets("Template").Visible = True For Each MyCell In MyRange Sheets("Template").Copy After:=Sheets(Sheets.Count) ActiveSheet.Name = MyCell.Value ' renames the new worksheet Range("F3").Value = MyCell.Value Range("F4").Value = MyCell.Offset(0, 1).Value Next MyCell Sheets("Template").Visible = False End Sub4 Oct 2016 à 12:10
Apologies, I now understand what I had done, the room name list I used was a longer one and yes there was a duplicate.
I guess I need to now work on a way of it looking at the Room Name and the Level, so it won't see it as a duplicate.
Thanks so much again for your help.
Kind regards
Rachael