Add worksheets to excel workbook using count defined name
Solved/Closed
raungst98
Posts
1
Registration date
Sunday April 24, 2016
Status
Member
Last seen
April 24, 2016
-
Apr 24, 2016 at 04:45 PM
raungst98 - Apr 27, 2016 at 01:57 AM
raungst98 - Apr 27, 2016 at 01:57 AM
Related:
- Add worksheets to excel workbook using count defined name
- 2007 microsoft office add-in microsoft save as pdf or xps - Download - Other
- Add gif to excel - Guide
- How to add songs to sound picker - Guide
- How to add @ in laptop - Guide
- Transfer data from one excel worksheet to another automatically - Guide
1 response
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Apr 25, 2016 at 11:44 AM
Apr 25, 2016 at 11:44 AM
Hi Raungst98,
This is what I get from your query:
You have a number in B4 on sheet QRY-CMW.
This number represents the amount of sheets you want to add after sheet QRY-CMW.
Example:
If the number 3 is in B4 the the first sheet will be created:
TABS: "QRY-CMW" - "TENANT 1"
Then the next:
TABS: "QRY-CMW" - "TENANT 2" - "TENANT 1"
And the next:
TABS: "QRY-CMW" - "TENANT 3" - "TENANT 2" - "TENANT 1"
This is done by the following code:
If you rather have the following result:
TABS: "QRY-CMW" - "TENANT 1" - "TENANT 2" - "TENANT 3"
Then use this code:
Hopefully I understood you correctly and this helped you out.
Best regards,
Trowa
This is what I get from your query:
You have a number in B4 on sheet QRY-CMW.
This number represents the amount of sheets you want to add after sheet QRY-CMW.
Example:
If the number 3 is in B4 the the first sheet will be created:
TABS: "QRY-CMW" - "TENANT 1"
Then the next:
TABS: "QRY-CMW" - "TENANT 2" - "TENANT 1"
And the next:
TABS: "QRY-CMW" - "TENANT 3" - "TENANT 2" - "TENANT 1"
This is done by the following code:
Sub RunMe() Dim x, AddSheets As Integer AddSheets = Sheets("QRY-CMW").Range("B4").Value Do x = x + 1 Worksheets.Add after:=Sheets("QRY-CMW") ActiveSheet.Name = "TENANT " & x Loop Until x = AddSheets End Sub
If you rather have the following result:
TABS: "QRY-CMW" - "TENANT 1" - "TENANT 2" - "TENANT 3"
Then use this code:
Sub RunMe() Dim x, AddSheets As Integer AddSheets = Sheets("QRY-CMW").Range("B4").Value Do x = x + 1 Worksheets.Add after:=Sheets(Sheets.Count) ActiveSheet.Name = "TENANT " & x Loop Until x = AddSheets End Sub
Hopefully I understood you correctly and this helped you out.
Best regards,
Trowa
Apr 27, 2016 at 01:57 AM
R