PC Review


Reply
Thread Tools Rate Thread

Active worksheet problem

 
 
=?Utf-8?B?ZGpk?=
Guest
Posts: n/a
 
      13th Sep 2007
I have a subroutine that has been working fine until I added 3 worksheets
from another workbook. It seems that when I activate a worksheet then refer
to the ActiveSheet that I am getting a different worksheet. Here is a
portion of the code.

Worksheets("RatesByLevel").Activate

b_end = False

'*** First row contains query name and 2nd row contains Column headings so
start at the 3nd row on the sheet
'*** by initalizing the counter to 2.
i_rownum = 2

'*** Using Base 0 array so set the indexes to their initial setting
i_indxGeo = 0
i_indxLoc = 0

'*** Loop through the entire worksheet until we hit a blank geo value **
Do Until b_end
i_rownum = i_rownum + 1

'*** End the loop when we come to a blank row ***
If ActiveSheet.Range("C" & i_rownum) = "" Then
b_end = True
Else

The worksheet activate is activating Sheet 12 but the ActiveSheet statement
is accessing Sheet 20.
 
Reply With Quote
 
 
 
 
Mike Fogleman
Guest
Posts: n/a
 
      13th Sep 2007
That is curious. In the VBEditor under your workbook project, is the sheet
you want the code to run on listed as:
Sheet12 ("RatesByLevel") ?
What is the tab name of Sheet20 ("Tab Name")
Does anything in the list of sheets look out of order or unusual?
Is there any Worksheet_Activate code on Sheet12 that could be sending the
focus to another sheet?

Mike F
"djd" <(E-Mail Removed)> wrote in message
news:CAD0287C-8DAE-4E0C-9D7F-(E-Mail Removed)...
>I have a subroutine that has been working fine until I added 3 worksheets
> from another workbook. It seems that when I activate a worksheet then
> refer
> to the ActiveSheet that I am getting a different worksheet. Here is a
> portion of the code.
>
> Worksheets("RatesByLevel").Activate
>
> b_end = False
>
> '*** First row contains query name and 2nd row contains Column headings so
> start at the 3nd row on the sheet
> '*** by initalizing the counter to 2.
> i_rownum = 2
>
> '*** Using Base 0 array so set the indexes to their initial setting
> i_indxGeo = 0
> i_indxLoc = 0
>
> '*** Loop through the entire worksheet until we hit a blank geo value **
> Do Until b_end
> i_rownum = i_rownum + 1
>
> '*** End the loop when we come to a blank row ***
> If ActiveSheet.Range("C" & i_rownum) = "" Then
> b_end = True
> Else
>
> The worksheet activate is activating Sheet 12 but the ActiveSheet
> statement
> is accessing Sheet 20.



 
Reply With Quote
 
=?Utf-8?B?ZGpk?=
Guest
Posts: n/a
 
      13th Sep 2007
I have checked those worksheets as well as the 3 worksheets that I copied
into the workbook and didn't find any code. All the logic is in a module. I
actually got the sheet numbers backward. The RatesByLevel is sheet 20 - the
data is being pulled off sheet 12. Problem occurs later in the routine
where I activate sheet 13 but the activesheet statement is pointing at sheet
7. I have 24 sheets in this workbook but I wouldn't think that would be
problem.

Right now I am going through and fully qualifying the references by
replacing the activesheet.range with workbooks("sheetname").range to see if
that gets me around the problem.

"Mike Fogleman" wrote:

> That is curious. In the VBEditor under your workbook project, is the sheet
> you want the code to run on listed as:
> Sheet12 ("RatesByLevel") ?
> What is the tab name of Sheet20 ("Tab Name")
> Does anything in the list of sheets look out of order or unusual?
> Is there any Worksheet_Activate code on Sheet12 that could be sending the
> focus to another sheet?
>
> Mike F
> "djd" <(E-Mail Removed)> wrote in message
> news:CAD0287C-8DAE-4E0C-9D7F-(E-Mail Removed)...
> >I have a subroutine that has been working fine until I added 3 worksheets
> > from another workbook. It seems that when I activate a worksheet then
> > refer
> > to the ActiveSheet that I am getting a different worksheet. Here is a
> > portion of the code.
> >
> > Worksheets("RatesByLevel").Activate
> >
> > b_end = False
> >
> > '*** First row contains query name and 2nd row contains Column headings so
> > start at the 3nd row on the sheet
> > '*** by initalizing the counter to 2.
> > i_rownum = 2
> >
> > '*** Using Base 0 array so set the indexes to their initial setting
> > i_indxGeo = 0
> > i_indxLoc = 0
> >
> > '*** Loop through the entire worksheet until we hit a blank geo value **
> > Do Until b_end
> > i_rownum = i_rownum + 1
> >
> > '*** End the loop when we come to a blank row ***
> > If ActiveSheet.Range("C" & i_rownum) = "" Then
> > b_end = True
> > Else
> >
> > The worksheet activate is activating Sheet 12 but the ActiveSheet
> > statement
> > is accessing Sheet 20.

>
>
>

 
Reply With Quote
 
Mike Fogleman
Guest
Posts: n/a
 
      14th Sep 2007
That sounds like a good idea. You rarely need to activate a sheet, so just
qualifying the sheets and their ranges is just good code practice and it
runs smoother in the background.
Good Luck, Mike F
"djd" <(E-Mail Removed)> wrote in message
news:740EBBD9-E4FD-4F6E-A9D5-(E-Mail Removed)...
>I have checked those worksheets as well as the 3 worksheets that I copied
> into the workbook and didn't find any code. All the logic is in a module.
> I
> actually got the sheet numbers backward. The RatesByLevel is sheet 20 -
> the
> data is being pulled off sheet 12. Problem occurs later in the routine
> where I activate sheet 13 but the activesheet statement is pointing at
> sheet
> 7. I have 24 sheets in this workbook but I wouldn't think that would be
> problem.
>
> Right now I am going through and fully qualifying the references by
> replacing the activesheet.range with workbooks("sheetname").range to see
> if
> that gets me around the problem.
>
> "Mike Fogleman" wrote:
>
>> That is curious. In the VBEditor under your workbook project, is the
>> sheet
>> you want the code to run on listed as:
>> Sheet12 ("RatesByLevel") ?
>> What is the tab name of Sheet20 ("Tab Name")
>> Does anything in the list of sheets look out of order or unusual?
>> Is there any Worksheet_Activate code on Sheet12 that could be sending the
>> focus to another sheet?
>>
>> Mike F
>> "djd" <(E-Mail Removed)> wrote in message
>> news:CAD0287C-8DAE-4E0C-9D7F-(E-Mail Removed)...
>> >I have a subroutine that has been working fine until I added 3
>> >worksheets
>> > from another workbook. It seems that when I activate a worksheet then
>> > refer
>> > to the ActiveSheet that I am getting a different worksheet. Here is a
>> > portion of the code.
>> >
>> > Worksheets("RatesByLevel").Activate
>> >
>> > b_end = False
>> >
>> > '*** First row contains query name and 2nd row contains Column headings
>> > so
>> > start at the 3nd row on the sheet
>> > '*** by initalizing the counter to 2.
>> > i_rownum = 2
>> >
>> > '*** Using Base 0 array so set the indexes to their initial setting
>> > i_indxGeo = 0
>> > i_indxLoc = 0
>> >
>> > '*** Loop through the entire worksheet until we hit a blank geo value
>> > **
>> > Do Until b_end
>> > i_rownum = i_rownum + 1
>> >
>> > '*** End the loop when we come to a blank row ***
>> > If ActiveSheet.Range("C" & i_rownum) = "" Then
>> > b_end = True
>> > Else
>> >
>> > The worksheet activate is activating Sheet 12 but the ActiveSheet
>> > statement
>> > is accessing Sheet 20.

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying the active worksheet to another worksheet in the same work queenmaam Microsoft Excel Worksheet Functions 5 25th Mar 2008 06:56 PM
Deleting column in a worksheet that is not active worksheet kansaskannan@gmail.com Microsoft Excel Programming 3 7th Oct 2007 03:33 PM
Basic Question - How do I return the worksheet number of the active worksheet? Regnab Microsoft Excel Programming 2 17th May 2006 03:02 AM
Altering code to reference the worksheet before the active worksheet KimberlyC Microsoft Excel Programming 8 15th Mar 2005 10:26 PM
macro to apply worksheet event to active worksheet Paul Simon Microsoft Excel Programming 3 7th Aug 2003 02:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:51 PM.