Copying sheet based on items in a list.

rakeshplb

New Member
Joined
Apr 3, 2009
Messages
31
Hello all,

I have two sheets in a workbook, they are named as "List" and "Original"

I have a list of 'strings' (like apple, banana etc.) in a column A of the sheet called "List". The list has somewhere around 25 to 50 items.

I want -

  1. To make copies of sheet "Original". One copy for each item on "List".
  2. Each copy of sheet should be named based on the item name in list, leaving the first two characters of the string out - like for a string called apple, the sheet should be named as "ple", for "Banana" the sheet should be called as "nana" etc.
  3. Cell "A2" of each should have the full "string", like "Apple", "Banana" etc.
So in the end result the workbook will have -

  1. Sheet "List" unaltered.
  2. Sheet "Original" unaltered.
  3. Sheet "ple" - copy of "Original", cell A2 should have "Apple"
  4. Sheet "nana" - copy of "Original", cell A2 should have "Banana" and so on...
Is this something possible? I have so far been able to make copies of "Original" based on count of items in the "List", do not know how to move forward.

Can some one give me those precious bits of code to make this happen?

Thank you so much!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi there,

Easy to do, but what row does your list in column A of the original sheet start on? Or is that not relevant?
 
Upvote 0
Hi there,

Easy to do, but what row does your list in column A of the original sheet start on? Or is that not relevant?
Thanks AnAnalyst.

It starts from cell A2 (A1 is header) on sheet "List". Sheet "Original" has dozen of columns and rows.
 
Upvote 0
Hi there,

Try this:

Code:
Sub CopyOriginal()
    Dim rngList As Range
    Dim rngCell As Object
    Dim shtList As Worksheet
    Dim shtOriginal As Worksheet
    Dim shtCopy As Worksheet
    Dim strItem As String
    Dim strShortCode As String
    
    Set shtList = Sheets("List")
    Set shtOriginal = Sheets("Original")
    Set rngList = shtList.Range("A2:A" & shtList.Range("A" & Rows.Count).End(xlUp).Row)
    
    For Each rngCell In rngList.Cells
        strItem = rngCell.Value
        strShortCode = Mid(strItem, 3, 255)
        shtOriginal.Copy after:=Sheets(Sheets.Count)
        Set shtCopy = ActiveSheet
        With shtCopy
            .Name = strShortCode
            .[A2].Value = strItem
        End With
     
    Next rngCell
    
    Set shtList = Nothing
    Set shtOriginal = Nothing
    Set rngList = Nothing
    Set shtCopy = Nothing
    
End Sub
 
Upvote 0
Wonderful AnAnalyst!

You have helped me a big way. Saved me from one full night of efforts, each month.

Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top