Programming the Command button

  • Thread starter Thread starter rink2
  • Start date Start date
Sheets("Draft Order Enrollee Record").Select Range("B1").Select

When you are selecting a new sheet and a range on that sheet, use two lines:

Sheets("Draft Order Enrollee Record").Select
Range("B1").Select

This applies to all of the lines in your code where you are using
Range("B1").Select This will reduce the likelyhood of generating error
messages and will ensure that Range B1 on the correct sheet is selected.
Otherwise, it could simply select B1 on the last active sheet and not send an
error message, so you would not know that an error had occurred.
 
If this code is still behind the worksheet that contains that commandbutton, the
code will have to look more like:

Sheets("Draft Order Enrollee Record").Select
Sheets("Draft Order Enrollee Record").Range("B1").Select

That second line has an unqualified range and unqualified ranges behind
worksheets refer to sheet that owns the code.

And when the code tries to select a cell on a sheet that isn't active, it'll
blow up.
 
If this code is still behind the worksheet that contains that commandbutton, the
code will have to look more like:

Sheets("Draft Order Enrollee Record").Select
Sheets("Draft Order Enrollee Record").Range("B1").Select

That second line has an unqualified range and unqualified ranges behind
worksheets refer to sheet that owns the code.

And when the code tries to select a cell on a sheet that isn't active, it'll
blow up.










--

Dave Peterson- Hide quoted text -

- Show quoted text -

Yes, you are correct. I was getting to the correct worksheet but not
the correct cell. I did as you suggested and now it takes me to the
correct sheet and cell.

Thank you very much,

Bob
 
Another way to do it would have been to use the application.goto

Application.Goto Worksheets("NPDES Ind Order").Range("B1")
or
Application.Goto Worksheets("NPDES Ind Order").Range("B1"), Scroll:=true



rink wrote:
 

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

Back
Top