Excel - why doesn't this work?
Anyone tell me why the following code acts the way it does.
I have a form that holds my print routines. The following code is stored in the form.
shortened version of my code...
[Highlight=VB]
If optA.Value = True Then Set RngSelectedPrint = Sheets("One").Range("A1:k100")
If optB.Value = True Then Set RngSelectedPrint = Sheets("Two").Range("A1", Range("a1").End(xlDown).End(xlToRight))
RngSelectedPrint.Preview ' or RngSelectedPrint.PrintOut
[Highlight=VB]
I do have two option buttons on my form, one called optA, the other called optB.
Problem is not the code doesn't word - it does. It just doesn't work consistently.
From sheet One - I can select option A. Option B gives me a run time error #1004. Code never makes it past the if optB line.
From sheet Two - I can select both options. They both work.
Now, if optB didn't work at all, I would understand it. If my reference works once, why does it not work irrelevant of the sheet from which the form is called.