save file as different name until cell is blank

P

Pam M

I have a worksheet that needs to be saved in anywhere from 1 to 6 different
locations depending on the contents of cells AH1 through AH6 (this is where
the filenames are stored). I want the macro to save to all filenames in
this range, but I don't want a runtime error when one of the cells is blank,
for example if there are only 4 filenames instead of 6. Presently, my code
is

Sub Save_to_root()
Dim fname
With ActiveWorkbook
fname = .Worksheets("Daily").Range("AH1").Value & ".xls"
..SaveAs fname
End With
End Sub

Can someone help with the adjustment? Thanks, Pam
 
R

Ron de Bruin

Hi Pam

Try this
Note: I use SaveCopyAs

Sub test()
Dim fname As String

For I = 1 To 6
With ActiveWorkbook
If .Worksheets("Daily").Range("AH" & I).Value <> "" Then
fname = .Worksheets("Daily").Range("AH" & I).Value & ".xls"
.SaveCopyAs fname
End If
End With

Next I
End Sub
 
P

Patrick Molloy

newsreader probs - sorry for double post

Patrick Molloy said:
Sub Save_to_root()
Dim fname
dim cell as range
With ActiveWorkbook
for each cell in .Worksheets("Daily").Range("AH1:AH6").Cells
if cell.value<>"" then
fname = cell.Value & ".xls"
.SaveAs fname
end if
next
End With
End Sub
 
P

Pam M

These both worked well. I chose Rons because it allowed the file to stay
where it was while just depositing a copy which set me up for the next macro
save that I needed to do. Thanks so much to you both! Pam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top