Paste Value from List into Separate Sheets

ramkrau

New Member
Joined
Jan 9, 2019
Messages
14
I need some help - google hasn't led me to anything useful :(

In my workbook, Sheet1 is a template used to analyze some data. Sheet2 is a list of values. My current macro asks a user how many times they need the template copied, and then copies Sheet1 as a new tab at the end of the workbook the requested number of times. I need to update this and do some more automation, but I just don't know how.

First, I want to automatically count the number of values in my list and use that count to tell my macro how many new tabs to create. Then, each new tab needs to have a value from the list copied and pasted into cell C3.

For example:
Sheet2's list in Column A might have 3 values:

Apple
Boat
Potato

I want the macro to count that there are three values, and then copy the first value paste into C3 in the first new tab, second value from the list and paste into C3 in the second new tab, third value from the list and paste into C3 in the third new tab.

So,
NewTab1.C3 = Apple
NewTab2.C3 = Boat
NewTab3.C3 = Potato

My current code isn't really powerful. Can anyone help me with some of this automation???? Pretty please?!?!?!?



VBA Code:
Sub CopyConfigRequest()
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate
Dim n As Integer
    On Error Resume Next
    n = InputBox("How many copies of the configuration request sheet do you want to make?")
 
    If n >= 1 Then
        For numtimes = 1 To n
            ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
        Next
    End If
Worksheets("Sheet2").Activate
Application.ScreenUpdating = True
Call wkstcolor
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
This is probably far from the best alternative, but I believe it works under your described conditions.

Code:
Sub CopyConfigRequest()
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate
Dim n As Integer
    On Error Resume Next
    'n = InputBox("How many copies of the configuration request sheet do you want to make?")
    n = WorksheetFunction.CountA(Sheets("Sheet2").Range("A:A"))
    If n >= 1 Then
        For numtimes = 1 To n
            ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
            Sheets("Sheet1 " & "(" & (numtimes + 1) & ")").Range("C3") = Sheets("Sheet2").Range("A" & numtimes)
        Next
    End If
Worksheets("Sheet2").Activate
Application.ScreenUpdating = True
' Call wkstcolor
End Sub
 
Upvote 0
This is probably far from the best alternative, but I believe it works under your described conditions.

Code:
Sub CopyConfigRequest()
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate
Dim n As Integer
    On Error Resume Next
    'n = InputBox("How many copies of the configuration request sheet do you want to make?")
    n = WorksheetFunction.CountA(Sheets("Sheet2").Range("A:A"))
    If n >= 1 Then
        For numtimes = 1 To n
            ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
            Sheets("Sheet1 " & "(" & (numtimes + 1) & ")").Range("C3") = Sheets("Sheet2").Range("A" & numtimes)
        Next
    End If
Worksheets("Sheet2").Activate
Application.ScreenUpdating = True
' Call wkstcolor
End Sub



So, I gave this a shot and immediately found one correction I had to make...
VBA Code:
    n = WorksheetFunction.CountA(Sheets("Sheet2").Range("A:A"))
had to become
VBA Code:
    n = WorksheetFunction.CountA(Sheets("Sheet2").Range("A2:A200"))
so that it wouldn't count the header row in the worksheet. That's easy enough to fix...

But, the issue is that it still isn't doing the value paste that I really need...

In "Sheet2" cells A2:A200 represent a list of items... for example, if I have three things to list, they might be:

Apple
Boat
Potato

The goal is that after the macro counts that there are three things, and then creates the three new tabs, I would then like the for first new tab to pull the first item in my list (Apple) and paste that into cell C3 of that tab, the second new tab should pull the second item from the list (Boat) and past that into cell C3 of that tab, the third new tab to pull the third item from the list (Potato) and past that into C3 of that tab. That is the most important part of the script and the part that isn't working just yet.

I suspect it could be something with this line of your suggestion:
VBA Code:
            Sheets("Sheet1 " & "(" & (numtimes + 1) & ")").Range("C3") = Sheets("Sheet2").Range("A" & numtimes)
because the behavior of the script doesn't change even if I comment that line out.

Any additional help would be SUPER appreciated!!!!!!!!!!!
 
Upvote 0
How about this modification?

Code:
Sub CopyConfigRequest()
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate
Dim n As Integer
    On Error Resume Next
    'n = InputBox("How many copies of the configuration request sheet do you want to make?")
    n = WorksheetFunction.CountA(Sheets("Sheet2").Range("A2:A200"))
    If n >= 1 Then
        For numtimes = 1 To n
            ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
            Sheets("Sheet1 " & "(" & (numtimes + 1) & ")").Range("C3") = Sheets("Sheet2").Range("A" & numtimes + 1)
        Next
    End If
Worksheets("Sheet2").Activate
Application.ScreenUpdating = True
' Call wkstcolor
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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