Macro to Change name in cell and print to pdf and repeat

gsater

New Member
Joined
May 27, 2014
Messages
1
Asking for help to have a macro to change cell C9 to customer name in cell T3, then print to pdf. Once printed, change cell C9 to customer name in T4 and print to pdf. I have the printind to pdf working, but changing cell value is messing me up. Any help would be appricated.

Cell C9 currently selected:
Sub Print_Sheet()

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, ActiveCell) Is Nothing Then
ActiveCell.Value = Sheets("sheet name").Range("
t4")
End If

ChDir "Change to directory & folder wanting to save pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"Change to directory & folder wanting to save pdf\" & Range("U1").Text & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

If Not Intersect(Target, ActiveCell) Is Nothing Then
ActiveCell.Value = Sheets("sheet name").Range("
t5")
End If

ChDir "Change to directory & folder wanting to save pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"Change to directory & folder wanting to save pdf\" & Range("U1").Text & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi and welcome to the forum.

Maybe something like this...

Code:
[color=darkblue]Sub[/color] Print_Sheet()
    
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Range("T3", Range("T" & Rows.Count).End(xlUp)) [color=green]'T3 to last used cell in column T[/color]
        
        Range("C9").Value = cell.Value
        
        [color=green]'ChDir "Change to directory & folder wanting to save pdf"[/color]
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "Change to directory & folder wanting to save pdf\" & Range("U1").Text & ".pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
            
    [color=darkblue]Next[/color] cell
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Hi and welcome to the forum.

Maybe something like this...

Code:
[COLOR=darkblue]Sub[/COLOR] Print_Sheet()
    
    [COLOR=darkblue]Dim[/COLOR] cell [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] cell [COLOR=darkblue]In[/COLOR] Range("T3", Range("T" & Rows.Count).End(xlUp)) [COLOR=green]'T3 to last used cell in column T[/COLOR]
        
        Range("C9").Value = cell.Value
        
        [COLOR=green]'ChDir "Change to directory & folder wanting to save pdf"[/COLOR]
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "Change to directory & folder wanting to save pdf\" & Range("U1").Text & ".pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
            
    [COLOR=darkblue]Next[/COLOR] cell
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]



What if T3 and C9 were on two different Sheets?

Say.......
T3 (Sheet1)
C9 (Sheet3)
 
Upvote 0
Qualify the sheets like this...

Code:
[COLOR=darkblue]Sub[/COLOR] Print_Sheet()
    
    [COLOR=darkblue]Dim[/COLOR] cell [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] cell [COLOR=darkblue]In[/COLOR] [B]Sheets("Sheet1").[/B]Range("T3", [B]Sheets("Sheet1").[/B]Range("T" & Rows.Count).End(xlUp)) [COLOR=green]'T3 to last used cell in column T[/COLOR]
        
        [B]Sheets("Sheet3").[/B]Range("C9").Value = cell.Value
        
        [COLOR=green]'ChDir "Change to directory & folder wanting to save pdf"[/COLOR]
        [B]Sheets("Sheet3").[/B]ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "Change to directory & folder wanting to save pdf\" & [B]Sheets("Sheet3").[/B]Range("U1").Text & ".pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
            
    [COLOR=darkblue]Next[/COLOR] cell
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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