VBA to search multiple cells.

Giulianeo

New Member
Joined
Sep 26, 2019
Messages
12
Hey guys,

I have this simple code to export as PDF, range AB52 is where it pulls the file name to save as... is it possible to have multiple ranges for the code to look for? I tried "range ("AB52:AB54")" would not work. Is this even possible? If one cell is empty look on the other ones for the file name?

Thank you!

VBA Code:
Sub Saveworksheetaspedfinwalmartfolder()

'Save Active Sheet(s) as PDF

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="V:\DEPARTMENTS\TRAINING\COORDINATION\Invoicing Backup\" & Range("AB52"), openafterpublish:=True

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi

VBA Code:
Sub Saveworksheetaspedfinwalmartfolder()
'Save Active Sheet(s) as PDF
Dim i As Integer
For i = 52 to 54
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="V:\DEPARTMENTS\TRAINING\COORDINATION\Invoicing Backup\" & Range("AB" & i), openafterpublish:=True
Next i
End Sub

Hope this will help
 
Upvote 0
Hi

VBA Code:
Sub Saveworksheetaspedfinwalmartfolder()
'Save Active Sheet(s) as PDF
Dim i As Integer
For i = 52 to 54
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="V:\DEPARTMENTS\TRAINING\COORDINATION\Invoicing Backup\" & Range("AB" & i), openafterpublish:=True
Next i
End Sub

Hope this will help
Thank you! I was able to resolve it by using the IF statement to test different conditions however this will come in handy for something else I have! Would you happen to know if it is possible to..
VBA Code:
Sub Saveworksheetaspedfinwalmartfolder()

'Save Active Sheet(s) as PDF

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="V:\DEPARTMENTS\TRAINING\COORDINATION\Invoicing Backup\" & Range("AB52"), openafterpublish:=True

End Sub

Add regular text to display after Range("AB52"), "_SS", so that the words _SS display after the text pulled from cell AB52?

Thank you!
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
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