Using a macro to save a file based on text in a cell

kw127533

New Member
Joined
Jul 14, 2014
Messages
3
Hi All,

I have the below macro that I've been using to select data from a sheet, copy the data, open a new workbook, paste special values and format columns C & D to date format. This works perfectly as is, however, instead of the filename for the new workbook being based off of cell H1 in worksheet "Upload to NBI" I would like it to be based on cell B10 from the "Contacts" sheet. I tried using Sheets ("Contacts").Range ("B10").text instead of Range("H1").text but it errors. Here is the code I currently have:

Sub Upload_NBI()
'
' Upload_NBI Macro

Sheets("Upload to NBI").Select
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:E").Select
Columns("A:E").EntireColumn.AutoFit
Columns("C:D").Select
Selection.NumberFormat = "m/d/yyyy"
Range("A1").Select
Application.CutCopyMode = False
ChDir "\\Yydafs-data1\department\CIT\CIT_Admin\NBI\Project Plan Upload Files"
ActiveWorkbook.SaveAs Filename:= _
"\\Yydafs-data1\department\CIT\CIT_Admin\NBI\Project Plan Upload Files\" & Range("H1").Text & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Sheets("Contacts").Select

I would also like this code to loop and save separate files based on the values in cells B11-B19 (if they are not blank). For example, if B11 is blank stop, else save file and name based on text in B11, if B12 is blank stop, etc.

I'm new to VBA so any help is appreciated!!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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