VBA code - to copy a name from a list to a template

Jo Ann Kaminski

New Member
Joined
Mar 7, 2023
Messages
7
I have the below VBA code that is working well for my task but I'd like to expand this to include the name from the list into the template that is created. There is line of code that indicates it could be used to make this happen, which I have underlined below - I just don't know how to make it work?

Sub SaveMasterAs()

'Excel 10 Tutorial

Dim wb As Workbook

Dim rNames As Range, c As Range, r As Range

'Current file's list of names and ids on sheet1.

Set rNames = Worksheets("Sheet1").Range("A2", Worksheets("Sheet1").Range("A2").End(xlDown))

'Path and name to master workbook to open for copy, saveas.

Set wb = Workbooks.Open(ThisWorkbook.Path & "\Template.xlsx")

For Each c In rNames

With wb

'If You Need To Copy Something To the Template Use this line

.Worksheets("Sheet1").Range("A1").Value = c.Offset(, 1).Value 'ID

'Path and name for copied workbook

.SaveAs Filename:=ThisWorkbook.Path & "\Template Copy\" & c.Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

End With

Set wb = ActiveWorkbook

Next c

wb.Close

End Sub
 
What's going on DanteAmor?
Did your crystal ball break? and you don't see the file anymore?
Sin. It needs to be repaired... :):);)
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I'm sorry, although I'd like to, I can't provide further assistance without the proper data. It is difficult to guess the name of your sheets in each book, how many sheets you have in each book, what is the name of each book, and also you modify the macro and make me responsible for the errors of the macro.
So sorry! I thought the picture I attached was what you needed to show you the names of the tabs in the workbook. I do appreciate your assistance to this point and I by no means was holding you accountable for the errors. This is on me.
 
Upvote 0
Can I ask if you can take one more look? I feel we are so close to fixing this and making it work. If not would anyone else be willing to give this a try? Really could use the help.
 
Upvote 0
This is where you should put all the relevant information about your books, book names, sheet names, how many sheets you have in each book, etc, etc.


By the way. The name of the sheet is not visible in this image:

1678293441379.png


So, in order for you to receive help from me or someone else, you must provide all the information, complete, I already posted 3 codes and none of them work for you. I can't keep trying to guess how your sheets are.

It is also not enough to say: the macro does not work.

You must write here what you modified to the macro. Because each of the macros that I have given you works for me, but you modify them and then you simply come with your comment: it still doesn't work.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
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