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
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,988
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 :)
 

Watch MrExcel Video

Forum statistics

Threads
1,118,056
Messages
5,569,951
Members
412,299
Latest member
agentless
Top