Solved

Insert Worksheet Loop - Rename and unhide each sheet

Posted on 2011-03-19
10
360 Views
Last Modified: 2012-05-11
Hi there

I have a VBA macro that inserts X amount of a hidden worksheet into my workbook, however I can't seem to figure out how to unihide and rename these as they are being created by the loop. Can any VBA experts help me out please?
For Each c In Range("=Quotation!$A$6:$A$20")

    strName = "Item " & c.Value
    'Blank is the name of my template worksheet
    Sheets("Blank").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = strName
    ActiveSheet.Visible = True            

Next c

Open in new window

0
Comment
Question by:wellso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35171293
You are naming them in the loop ... do you want to later rename them?

Chris
0
 
LVL 2

Author Comment

by:wellso
ID: 35171295
Yeah I'd like name them item + c.value as they are being created if possible
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35171305
Item + c.value

Item is a string and you cannot algebraically add so can you explan what you want as a result as a text example?

Chris
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35171309
BTW you aren't hiding them in yur loop due to .visible = true rather false or xlhidden

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35171347
If I wasn't clear then you are creating a string as for example Assuming A6 contains myA6Text then

"Item myA6Text" and this is used to rename the newly inserted sheet.  The value updates for myA6Text with each time the loop proceeds.

A6 = myA6Text
First (Inserted) sheet becomes Item myA6Text by name
A6 = 22
First (Inserted) sheet becomes Item 22 by name

A7 = myA7Text
Second (Inserted) sheet becomes Item myA7Text by name

If the issue is with a rerun then either the sheets need deleting or you somehow need a note of the old name and then rename the sheet but first off to understand the problem.

Chris

Chris
0
 
LVL 2

Author Comment

by:wellso
ID: 35171348
I meant to use & instead of +, sorry, too much JavaScrpt :)

SO if I have the range 1,2,3,4,5 my new sheets will be

Item 1
Item 2
Item 3
Item 4

I want to unhide the sheets as they are created, not hide them. The orignal 'Blank' statys hidden.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 35171362
Try for example

Chris
Dim sh As Worksheet
For Each c In Range("=Quotation!$A$6:$A$20")

    strname = "Item " & c.Value
    'Blank is the name of my template worksheet
    Sheets("Blank").Copy After:=Sheets(Sheets.Count)
    Set sh = Sheets(Sheets.Count)
    sh.Name = strname
    sh.Visible = True 'xlHidden

Next c

Open in new window

0
 
LVL 2

Author Comment

by:wellso
ID: 35171371
Thanks bud thats pretty much it, but Item one seems to be a copy of a different sheet rather than''Blank'
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35171373
Have you tried deleting all the item sheets because as a loop it is difficult to see how it could differ perhaps item 1 is left over from a different naming sequence?

Chris
0
 
LVL 2

Author Closing Comment

by:wellso
ID: 35171443
Thankyou ever so much!
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question