Runtime Error.....Why???

roughleg

Board Regular
Joined
Jun 21, 2004
Messages
181
Hi All,
Can someone tell me what I'm doing wrong? I'm trying to print out a schedule each day that's created by filling out a form. After the schedule is made I want to set the print area and print the page based on what ever size it happens to be that day. I keep getting a run time error on the ActiveSheet line of this code:

Sub Button4_Click()

Dim LR As Integer
Dim LC As Integer
LR = Cells.Find("*", [A1], xlFormulas, xlPart, xlByRows, xlPrevious, False, False).Column
Worksheets("Schedule").Activate
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), Cells(LR, LC)).Address
Range(Cells(1, 1), Cells(LR, LC)).Select
ActiveSheet.PrintOut
Sheets("Menu").Select

End Sub

Please help,
Skip
 

Excel Facts

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

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,053
Office Version
  1. 365
You haven't set LC = to anything yet. Cells(LR,0) returns an error.

Also, you probably don't need "Range(Cells(1, 1), Cells(LR, LC)).Select"
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
You have not assigned a value to the LC variable, which is causing an error when you try to use cells(LR,LC).
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686

ADVERTISEMENT

uhhh...yeah. Set the column number to the LC variable. Fix it right up.
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Also, I just noticed you're setting LR as the column. May want to change that around.

Also also, if LR is going to be used to capture a row number, it should be dimmed as Long, not as an integer :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,994
Messages
5,834,775
Members
430,321
Latest member
yemisimi11

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
Top