VBA code that saves multiple excel files derived from table

coen078

New Member
Joined
May 6, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I want to write a macro that changes the value in A10 worksheet "blad1" with the values in the table P&ID in worksheet "blad 2" every time the value is changed it needs to save that excel file with that specific value and the file name needs to be the same as that value. So let's say i have 21 different blueprint numbers ranging from P&ID 100 until 120.
I want to create 21 different excel files with the file names "P&ID 100", "P&ID 101", "P&ID 102" etc...

I hope to save a lot of time with this macro instead of manually changing the number tens or hundreds of times and saving as a different file.

Sub SaveAsCell()
Dim strName As String


strName = Sheet1.Range("A10")
ActiveWorkbook.SaveAs strName
Exit Sub

End Sub

I have this as a starting point but i want to speed it up and have it do the whole table from a different worksheet.


1620304774332.png


1620304798257.png
 
I modified your cod a bit. Not sure if I helped but try this:
VBA Code:
Sub VoorbladenMaken()

  Dim strName As String
  Dim i As Integer
  i = 1
  
  Do While Sheets("Sheet2").Cells(1 + i, 1).Value <> ""
  
    Sheets("Sheet2").Cells(i + 1, 1).Copy Sheets("Sheet1").Range("A10")
    i = i + 1
    
    Worksheets("Sheet2").Visible = False
    
    strName = Sheets("Sheet1").Range("A10")
    ActiveWorkbook.SaveAs strName
    
    Worksheets("Sheet2").Visible = True
  
  Loop


End Sub
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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