Event Triggered in Wrong Sheet

C

Cassie

Hi,

I am using excel 2003 and have a workbook with 2 sheets and the code below
in "ThisWorkbook".

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Select
If Range("A1") = "" Then
Cancel = True
Range("A1").Select
MsgBox ("Type in the missing data...")
GoTo ExitNow
End If
ExitNow:
End Sub

If I leave cell A1 on Sheet1 blank, then click on Sheet2 and try to print,
it will place the cursor onto Sheet1 cell A1 and if I immediately type a
value and click enter, the value disappears from Sheet1 cell A1 and appears
in Sheet 2 cell A1.

Can anyone help?
 
M

Mike H

Cassie,

Your code can be simplified to that below but I can't see how your code (or
mine) would cause what you describe. Do you have any other code in the
workbook?

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Sheets("Sheet1").Range("A1") = "" Then
Cancel = True
Application.Goto Sheets("Sheet1").Range("A1")
MsgBox ("Type in the missing data...")
End If
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
P

PY & Associates

Hi,

I am using excel 2003 and have a workbook with 2 sheets and the code below
in "ThisWorkbook".

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Worksheets("Sheet1").Activate
    Worksheets("Sheet1").Select
    If Range("A1") = "" Then
            Cancel = True
            Range("A1").Select
            MsgBox ("Type in the missing data...")
            GoTo ExitNow
        End If
ExitNow:
End Sub

If I leave cell A1 on Sheet1 blank, then click on Sheet2 and try to print,
it will place the cursor onto Sheet1 cell A1 and if I immediately type a
value and click enter, the value disappears from Sheet1 cell A1 and appears
in Sheet 2 cell A1.

Can anyone help?

You can only type in a value AFTER you click OK to clear the message
box.
The moment you click OK, you are on the way to ExitNow and back to the
activesheet which is Sheet2
Your input value appears in sheet2 accordingly.
 
C

Cassie

Hi Mike,

To try and figure out this problem, I created an brand new workbook and it
only has the code in the "ThisWorkbook" module.

It's really bizarre!

I go to sheet 2 and try to print, it activates sheet1 and moves the cursor,
but unless I select the cell manually, my values are entered into sheet2.
As soon as I hit the enter key the values disappear from sheet 1 and go onto
sheet2.

Any more ideas??
 
C

Cassie

I realise you can only type in the value AFTER you click OK on the message,
I'm not a complete idiot.

As there is no value in Sheet1 cell A1, I would expect that after I click
OK, the active sheet should be sheet1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top