VBA Loop - calculate, save as pdf, next cell for each cell in range

djo5003

New Member
Joined
May 29, 2013
Messages
14
The project I am working on requires me to create different PDF reports for 40 different inputs—which are currently in a data validation list box (and also listed in a column on the spreadsheet). The workbook is set on manual calculation. For now, I am manually selecting the input in the data validation list drop down, recalculating the workbook, saving the worksheet as a PDF, and then repeating the process. I do this often enough where creating a VBA script to automatically cycle through the range of inputs, saving as a PDF after each recalculation, would save me a ton of time.

Thanks in advance.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Solved.

Code:
Sub LoopRange()


    Dim rCell As Range
    Dim rRng As Range
    Dim Name As String
    Dim Stamp As String
    Dim WhereTo As String
    Dim sFileName As String
    Dim FNameYearQuarter As String
    Dim FNameDRG As String


    Worksheets("Dashboard").Activate
    Set rRng = Range("A1:A19")


    For Each rCell In rRng.Cells
    
    Sheets("Dashboard").Range("I5").Value = rCell
        
'Begin updating sheet with active cell
       
    Application.ScreenUpdating = False


Sheets(Array("Dashboard 1", "Dashboard Detail")).Select


ActiveSheet.Calculate
  
'Place active cell at top left
   ' Range("A1").Select
    Application.Goto Range("A1"), True
    ActiveWindow.VisibleRange(1, 1).Select
    Sheets("Medical DRG Dashboard").Select
   ' Range("A1").Select
    Application.Goto Range("A1"), True
    ActiveWindow.VisibleRange(1, 1).Select


Application.ScreenUpdating = True
        
'Being PDF-ing
        
' Retrieve settings from the Form
Sheets(Array("Dashboard", "Dashboard Detail")).Select


' Assemble the filename
    FNameYearQuarter = Sheets("Dashboard").Range("A7").Value
    FNameDRG = Sheets("Dashboard").Range("Z5").Value
    sFileName = FNameYearQuarter & " Report - " & FNameDRG & ".pdf"
 
' Save the File as PDF
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\My Documents\" & sFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
    
' Make sure we open the Order Form upon Exit
    Sheets("Dashboard").Select
    
    Next rCell


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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