Help : Macro to save a woorksheet to a new workbook using data from a cell as the file name

srdear

New Member
Joined
Apr 20, 2014
Messages
4
Is it possible for a macro to save a worksheet to a different workbook with the "file name" coming from a cells data? I have a rental form that has a cell that is the invoice number. It increments by 1 each time a new form is opened. I would really like to save each invoice to a different workbook with the new file name being the invoice number when the "Done" command button is clicked. The other option would be for a "save as" dialog box to open and then manually type in the new name. But heck, why do that when a macro could do it for me?

Any help would be appreciated.

Steve
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is it possible for a macro to save a worksheet to a different workbook with the "file name" coming from a cells data? I have a rental form that has a cell that is the invoice number. It increments by 1 each time a new form is opened. I would really like to save each invoice to a different workbook with the new file name being the invoice number when the "Done" command button is clicked. The other option would be for a "save as" dialog box to open and then manually type in the new name. But heck, why do that when a macro could do it for me?

Any help would be appreciated.

Steve

You will have to change the cell reference to the one acturally holding the invoice number. This macro uses cell A2. It also assumes that the data to be saved is on the first sheet of the workbook.
Code:
Sub saveInv()
Sheets(1).Copy
ActiveWorkbook.SaveAs Sheets(1).[COLOR=#b22222]Range("A2")[/COLOR].Value & ".xlsx"
ActiveWorkbook.Close False
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,228
Messages
6,129,613
Members
449,520
Latest member
TBFrieds

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