Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
pt pt is offline
external usenet poster
 
Posts: 2
Default the default worksheet

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default the default worksheet

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
pt pt is offline
external usenet poster
 
Posts: 2
Default the default worksheet

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"
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default the default worksheet

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"
...
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
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
Default Settings for a New Worksheet billbrandi Excel Discussion (Misc queries) 1 September 25th 08 10:36 PM
Making a worksheet default Per[_2_] Excel Discussion (Misc queries) 1 March 28th 07 03:43 PM
How To Open First Worksheet By Default? Arif Excel Discussion (Misc queries) 3 August 1st 06 10:11 AM
default excel worksheet Jason - MR Excel Discussion (Misc queries) 4 December 27th 05 10:41 PM
Trying to set default Worksheet file name from C++/MFC Marc Applewhite Excel Programming 1 January 29th 05 11:14 PM


All times are GMT +1. The time now is 05:57 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"