Print Button and Lookup

Big_OT

New Member
Joined
Jan 17, 2018
Messages
7
Hello,

I have an excel document with a sheet for each month, I want to put a print macro button on each sheet which when pressed prints a certain range of the sheet, the range I want to print starts at A1 and finishes in column I, the row is based on how many entries there have been that month (and varies every month) and the last row of the range always has the word Total in column H.

I have tried this code but obviously the range changes and would be good to have it automatically update.
Code:
Sub PrintRange()
Range("A1:I50").PrintOut
End Sub
What would the best way to approach this be.
TIA
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
The following should work for you;

Code:
Sub PrintRange()
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ActiveSheet
LastRow = sht.Cells.Find("Total", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Range("A1:I" & LastRow).PrintOut
End Sub
 
Last edited:
Upvote 0
Am I able to have a confirmation window come up after I have pressed the Macro saying "are you sure you want to print" , "yes" , "no"

TIA
 
Upvote 0
Code:
Sub PrintRange()
Dim sht As Worksheet
Dim LastRow As Long
Dim answer As Integer
Set sht = ActiveSheet
LastRow = sht.Cells.Find("Total", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

answer = MsgBox("Are you sure you wish to print?", vbYesNo + vbQuestion, "Print Out")
If answer = vbYes Then
Range("A1:I" & LastRow).PrintOut
Else
'do nothing
End If
End Sub

Here you go
 
Upvote 0

Forum statistics

Threads
1,214,586
Messages
6,120,402
Members
448,958
Latest member
Hat4Life

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