PC Review


Reply
Thread Tools Rate Thread

the default worksheet

 
 
pt
Guest
Posts: n/a
 
      9th Apr 2010
hi,all:
I face a problem, I have a button control in worksheet 2,
and the code as below:

Private Sub CommandButton1_Click()
Worksheets(1).Activate
Cells(1, 1).Value = "kk"
End Sub

and It seems that worksheet 1 is activated ,but kk is
set at the worksheet 2's cell (1,1) not at the worksheet 1.
It seems that the defaultworksheet is not the active worksheet.
It is so strange. Why it is so?

many thanks,
PanTao


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      9th Apr 2010
If the code is in a general module, then the unqualified range belongs to the
activesheet.

If the code is behind a worksheet (and it is in your case), then the unqualified
ranges belong to the object owning the code -- the sheet with the commandbutton.

Private Sub CommandButton1_Click()
Worksheets(1).Activate 'you don't even need this line!
worksheets(1).Cells(1, 1).Value = "kk"
End Sub



pt wrote:
>
> hi,all:
> I face a problem, I have a button control in worksheet 2,
> and the code as below:
>
> Private Sub CommandButton1_Click()
> Worksheets(1).Activate
> Cells(1, 1).Value = "kk"
> End Sub
>
> and It seems that worksheet 1 is activated ,but kk is
> set at the worksheet 2's cell (1,1) not at the worksheet 1.
> It seems that the defaultworksheet is not the active worksheet.
> It is so strange. Why it is so?
>
> many thanks,
> PanTao


--

Dave Peterson
 
Reply With Quote
 
pt
Guest
Posts: n/a
 
      9th Apr 2010
Oh,I see, it is reasonable, many thanks ,Dave. And I had search the help of
EXCEL VBA
reference, but did't find it, all the explaination I found is that the
unqualified range belongs to
the activesheet. May you tell me Where can I find it?Many Thanks.

PanTao

--------------------------------------
"Dave Peterson" <(E-Mail Removed)>
??????:(E-Mail Removed)...
> If the code is in a general module, then the unqualified range belongs to
> the
> activesheet.
>
> If the code is behind a worksheet (and it is in your case), then the
> unqualified
> ranges belong to the object owning the code -- the sheet with the
> commandbutton.
>
> Private Sub CommandButton1_Click()
> Worksheets(1).Activate 'you don't even need this line!
> worksheets(1).Cells(1, 1).Value = "kk"
> End Sub
>
>
>
> pt wrote:
>>
>> hi,all:
>> I face a problem, I have a button control in worksheet 2,
>> and the code as below:
>>
>> Private Sub CommandButton1_Click()
>> Worksheets(1).Activate
>> Cells(1, 1).Value = "kk"
>> End Sub
>>
>> and It seems that worksheet 1 is activated ,but kk is
>> set at the worksheet 2's cell (1,1) not at the worksheet 1.
>> It seems that the defaultworksheet is not the active worksheet.
>> It is so strange. Why it is so?
>>
>> many thanks,
>> PanTao

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      9th Apr 2010
I've never looked for it.

But you can see it yourself.

Change your code (temporarily) to:

Private Sub CommandButton1_Click()
Worksheets(1).Activate
msgbox Cells(1, 1).parent.name
End Sub

(make sure that the worksheet with the button is not worksheets(1), though.)

pt wrote:
>
> Oh,I see, it is reasonable, many thanks ,Dave. And I had search the help of
> EXCEL VBA
> reference, but did't find it, all the explaination I found is that the
> unqualified range belongs to
> the activesheet. May you tell me Where can I find it?Many Thanks.
>
> PanTao
>
> --------------------------------------
> "Dave Peterson" <(E-Mail Removed)>
> ??????:(E-Mail Removed)...
> > If the code is in a general module, then the unqualified range belongs to
> > the
> > activesheet.
> >
> > If the code is behind a worksheet (and it is in your case), then the
> > unqualified
> > ranges belong to the object owning the code -- the sheet with the
> > commandbutton.
> >
> > Private Sub CommandButton1_Click()
> > Worksheets(1).Activate 'you don't even need this line!
> > worksheets(1).Cells(1, 1).Value = "kk"
> > End Sub
> >
> >
> >
> > pt wrote:
> >>
> >> hi,all:
> >> I face a problem, I have a button control in worksheet 2,
> >> and the code as below:
> >>
> >> Private Sub CommandButton1_Click()
> >> Worksheets(1).Activate
> >> Cells(1, 1).Value = "kk"
> >> End Sub
> >>
> >> and It seems that worksheet 1 is activated ,but kk is
> >> set at the worksheet 2's cell (1,1) not at the worksheet 1.
> >> It seems that the defaultworksheet is not the active worksheet.
> >> It is so strange. Why it is so?
> >>
> >> many thanks,
> >> PanTao

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
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
Default Worksheet OfficeChick Microsoft Access 0 10th Jul 2008 06:32 PM
How To Open First Worksheet By Default? Arif Microsoft Excel Misc 3 1st Aug 2006 10:11 AM
default excel worksheet =?Utf-8?B?SmFzb24gLSBNUg==?= Microsoft Excel Misc 4 27th Dec 2005 10:41 PM
Trying to set default Worksheet file name from C++/MFC =?Utf-8?B?TWFyYyBBcHBsZXdoaXRl?= Microsoft Excel Programming 1 29th Jan 2005 11:14 PM
Default Sheet in Worksheet francesca.foster@twi.co.uk Microsoft Excel Worksheet Functions 2 23rd Jan 2004 10:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 AM.