![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Location: New Zealand
Posts: 23
|
Hi All,
I have created a userform with a single refedit control (i.e. RefEdit1) and a single command button (i.e. CommandButton1). I also use code (see the end of the message) in the form. The select method works when the user uses refedit to select a range from the active worksheet. But, why does the select method fail when the user changes to another sheet and selects some cells on that sheet? What can I do to stop it failing? Thanks for your help. Andrew 'code in the userform Private Sub CommandButton1_Click() Dim SelRange As Range 'Get the user defined address, or reference, from the RefEdit control. Set SelRange = Range(RefEdit1.Value) SelRange.Select 'Unload the userform. Unload Me End Sub |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Let me get this straight. Let's say that Sheet1 is the activesheet. You want this code to select a cell on another sheet, for example, Sheet2?
If this is the case, the reason this fails is because you need to activate Sheet2 before trying to select a range on that sheet. Without looking too hard at what you need to do, you're to have to find a way to do something like:
HTH |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Try;
Private Sub CommandButton1_Click() Dim SelRange As Range 'Get the user defined address, or reference, from the RefEdit control. Set SelRange = Range(RefEdit1.Text) Application.Goto SelRange 'Unload the userform. Unload Me End Sub |
|
|
|
|
|
#4 |
|
New Member
Join Date: May 2002
Location: New Zealand
Posts: 23
|
Thanks Mark and Ivan. The "GOTO" method works. I hadn't realised that Select only works for the current worksheet (the help isn't explicit on that point).
Thanks very much for your help. Andrew |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|