Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
rci rci is offline
external usenet poster
 
Posts: 40
Default Perplexed...

Hi all...


odd thing... I have a worksheet_change event that fires fine... but
interestingly, in the code when I say:

Sheets("Sheet2").Select
Range("A5").Select

It will select the sheet, but will NOT select A5.

I wonder if the change function is doing this to prevent an infinite loop...

Hmmm...

How to get around this... (BTW, sheet2 does NOT have a change event)

Thx,

SMS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Perplexed...

When you refer to one sheet in code from anohter sheet you need to make the
full delclaration... try this

Sheets("Sheet5").Range("A5").Select


HTH

"rci" wrote:

Hi all...


odd thing... I have a worksheet_change event that fires fine... but
interestingly, in the code when I say:

Sheets("Sheet2").Select
Range("A5").Select

It will select the sheet, but will NOT select A5.

I wonder if the change function is doing this to prevent an infinite loop...

Hmmm...

How to get around this... (BTW, sheet2 does NOT have a change event)

Thx,

SMS


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Perplexed...

When you're in a General module, unqualified ranges (like Range("a5") refer to
the activesheet.

When you're in the worksheet module, this unqualified range refers to the sheet
that owns the code.

So if your worksheet_change even were for "Sheet1", your code is the same as:

sheets("sheet2").select
sheets("sheet1").range("a5").select

And you can't select a range unless that worksheet is active.

You could fully qualify the range like Jim wrote:

sheets("sheet2").select
Sheets("Sheet2").Range("A5").Select

or you could save some typing with the with/end with structu

with sheets("sheet2")
.select
.range("a5").select
end with

That being said, you can do most things without selecting the worksheet/range at
all.

with sheets("sheet2")
with .range("a5")
.value = "this is a test"
.numberformat="General"
end with
end with




rci wrote:

Hi all...

odd thing... I have a worksheet_change event that fires fine... but
interestingly, in the code when I say:

Sheets("Sheet2").Select
Range("A5").Select

It will select the sheet, but will NOT select A5.

I wonder if the change function is doing this to prevent an infinite loop...

Hmmm...

How to get around this... (BTW, sheet2 does NOT have a change event)

Thx,

SMS


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
rci rci is offline
external usenet poster
 
Posts: 40
Default Perplexed...

Thanks so much... I just moved all the code to a module, and I'm much
happier now :-)

SMS


Dave Peterson wrote:
: When you're in a General module, unqualified ranges (like Range("a5") refer to
: the activesheet.

: When you're in the worksheet module, this unqualified range refers to the sheet
: that owns the code.

: So if your worksheet_change even were for "Sheet1", your code is the same as:

: sheets("sheet2").select
: sheets("sheet1").range("a5").select

: And you can't select a range unless that worksheet is active.

: You could fully qualify the range like Jim wrote:

: sheets("sheet2").select
: Sheets("Sheet2").Range("A5").Select

: or you could save some typing with the with/end with structu

: with sheets("sheet2")
: .select
: .range("a5").select
: end with

: That being said, you can do most things without selecting the worksheet/range at
: all.

: with sheets("sheet2")
: with .range("a5")
: .value = "this is a test"
: .numberformat="General"
: end with
: end with


:

: rci wrote:
:
: Hi all...
:
: odd thing... I have a worksheet_change event that fires fine... but
: interestingly, in the code when I say:
:
: Sheets("Sheet2").Select
: Range("A5").Select
:
: It will select the sheet, but will NOT select A5.
:
: I wonder if the change function is doing this to prevent an infinite loop...
:
: Hmmm...
:
: How to get around this... (BTW, sheet2 does NOT have a change event)
:
: Thx,
:
: SMS

: --

: Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Perplexed...

Hello,

Not sure when I started to be able to replicate that error, but I can with
XP. Try the following:

Application.Goto Sheets("Sheet2").Range("A5")

Do not try:

Sheets("Sheet2").Range("A5").Select

If Sheet2 is not active, this will also give you an error.

Regards,
Nate Oliver


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perplexed scrabtree23[_3_] Excel Programming 3 December 5th 04 04:03 AM


All times are GMT +1. The time now is 09:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"