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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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"
 
Upvote 0
You have not assigned a value to the LC variable, which is causing an error when you try to use cells(LR,LC).
 
Upvote 0
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 :)
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,923
Members
448,533
Latest member
thietbibeboiwasaco

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