Run Code From Button and Save As PDF File

L

Legacy 436357

Guest
Hi,

I have this code which runs when cell H46 is changed. What I would like to do is have this code run by a button instead which also saves the print area B2:H53 of this sheet 'Lookup Invoice' to a PDF file.

Is this possible to do and if so how please?

Thank you very much

Code:
Dim xVal As String
Private Sub Worksheet_Change(ByVal Target As Range)
    Static xCount As Integer
    Application.EnableEvents = False
    If Target.Address = Range("H46").Address Then
        Range("J3").Offset(xCount, 0).Value = Range("H46").Value
        Range("K3").Offset(xCount, 0).Value = Range("H3").Value
        Range("L3").Offset(xCount, 0).Value = Format(Now(), "HH:MM:SS")
        xCount = xCount + 1
        
    Else
        If xVal <> Range("H44").Value Then
         Range("J3").Offset(xCount, 0).Value = Range("H46").Value
         Range("K3").Offset(xCount, 0).Value = Range("H3").Value
         Range("L3").Offset(xCount, 0).Value = Format(Now(), "MM/dd/yyyy HH:MM:SS")
         
        xCount = xCount + 1
        
        End If
    End If
    
    Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    xVal = Range("H46").Value
End Sub
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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