copying same tab several

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Copying same tab several times and changing just one cell

Copying same tab several times and changing just one cell

resolvedResolved · Medium Priority · Version 2010

Katherine has attended:
Excel Advanced course
Excel VBA Intro Intermediate course

Copying same tab several times and changing just one cell

I have got a worksheet set up which has one cell (made up of a 4 digit code) that can be changed. I need to be able to replicate the same worksheet for upto 100 other 4 digit codes which I have placed into a list on another worksheet within the same workbook.

Ideally, the VBA will also rename the worksheets so that it is the same as the 4 digit code.

Would this be possible to do with a VBA?

Many thanks,
Katherine

RE: Copying same tab several times and changing just one cell

Hi Katherine, thanks for your query. It certainly is possible! You will need to loop through that list, dropping each cell value into a value and then using:

Sheets.Add
Activesheet.name = thecode

The result will be a lot of new worksheets named after your 4 digit code!

Hope this helps,

Anthony

RE: Copying same tab several times and changing just one cell

Thank you for the response. I found the code below which allowed me to copy, then using the knowledge learned in the class and your response I managed to tweak it to work.

Thanks,
Katherine



Sub Copier2()
Dim x As Integer

x = InputBox("Enter number of times to copy Sheet1")
For numtimes = 1 To x
'Loop by using x as the index number to make x number copies.
'Replace "Sheet1" with the name of the sheet to be copied.
ActiveWorkbook.Sheets("Sheet1").Copy _
After:=ActiveWorkbook.Sheets("Sheet1")
Next
End Sub

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Formst Excel to display leading zeroes

Select the cells that you want to have displaying leading zeroes.

From the 'Format' menu select 'Cells' (Or Right-click on the selected range and and select 'Format Cells').

In the 'Number' tab click on 'Custom' in the 'Category' window.

In the 'Type:' box enter zeroes that correspond to the size of the required number (eg 5 zeroes).

Click OK.

When you enter numbers into these cells, leading zeroes will be displayed.

eg 123 = 00123

View all Excel hints and tips


Server loaded in 0.08 secs.