PC Review


Reply
Thread Tools Rate Thread

How can I select a range manually with the mouse?

 
 
ian
Guest
Posts: n/a
 
      25th Oct 2007
I like a macro which gives me control to select a range in a worksheet
manually, then continues with the macro.

I'd hoped to have a message box with something like "Select the range
to process" which I select off the worksheet with my mouse and then I
click ok to continue. I've googled and can'd find any pointers.

Can anyone help please?

Thanks

 
Reply With Quote
 
 
 
 
papou
Guest
Posts: n/a
 
      25th Oct 2007
Hello Ian

Use Application.Inputbox:

Dim MyRangeRef As Range
On Error GoTo Select_Cncled
Set MyRangeRef = Application.InputBox("Select the range of cells",
"Reference?", , , , , , 8)
Exit Sub

Select_Cncled:
MsgBox "you cancelled the previous message, you naughty!"

HTH
Cordially
Pascal

"ian" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
>I like a macro which gives me control to select a range in a worksheet
> manually, then continues with the macro.
>
> I'd hoped to have a message box with something like "Select the range
> to process" which I select off the worksheet with my mouse and then I
> click ok to continue. I've googled and can'd find any pointers.
>
> Can anyone help please?
>
> Thanks
>



 
Reply With Quote
 
papou
Guest
Posts: n/a
 
      25th Oct 2007
Even if it seems obvious, let me just indicate that you will then be able to
use the range for further actions before the "Exit Sub", eg:

Dim MyRangeRef As Range
On Error GoTo Select_Cncled
Set MyRangeRef = Application.InputBox("Select the range of cells",
"Reference?", , , , , , 8)
MsgBox MyRangeRef.Cells.Count
'do other stuff
'etc.
Exit Sub

Select_Cncled:
MsgBox "you cancelled the previous message, you naughty!"

HTH
Cordially
Pascal

"papou" <(E-Mail Removed)> a écrit dans le message
de news: %(E-Mail Removed)...
> Hello Ian
>
> Use Application.Inputbox:
>
> Dim MyRangeRef As Range
> On Error GoTo Select_Cncled
> Set MyRangeRef = Application.InputBox("Select the range of cells",
> "Reference?", , , , , , 8)
> Exit Sub
>
> Select_Cncled:
> MsgBox "you cancelled the previous message, you naughty!"
>
> HTH
> Cordially
> Pascal
>
> "ian" <(E-Mail Removed)> a écrit dans le message de news:
> (E-Mail Removed)...
>>I like a macro which gives me control to select a range in a worksheet
>> manually, then continues with the macro.
>>
>> I'd hoped to have a message box with something like "Select the range
>> to process" which I select off the worksheet with my mouse and then I
>> click ok to continue. I've googled and can'd find any pointers.
>>
>> Can anyone help please?
>>
>> Thanks
>>

>
>



 
Reply With Quote
 
ian
Guest
Posts: n/a
 
      25th Oct 2007
Pascal

Thanks. Never used an Application.Inputbox before. Always easy when
you know how.

I'm not often Naughty,

Ian

 
Reply With Quote
 
dan dungan
Guest
Posts: n/a
 
      26th Oct 2007
Hi,

The error handling didn't work for me using excel 2000 on xp.
If I didn't select a range and clicked ok, the procedure returned the
Dialog box-- The formula you typed contains an error.


On Oct 25, 3:24 pm, ian <ian.qmu...@googlemail.com> wrote:
> Pascal
>
> Thanks. Never used an Application.Inputbox before. Always easy when
> you know how.
>
> I'm not often Naughty,
>
> Ian



 
Reply With Quote
 
dan dungan
Guest
Posts: n/a
 
      26th Oct 2007
Sorry I sent the last message before I was finished typing.

Anyway, If I choose the cancel button, the procedure returns runtime
error 424--object required.

Also, I could never get the procedure to go to the error handler.

Please help me understand the error handling.

Thanks,

Dan

 
Reply With Quote
 
Basilisk96
Guest
Posts: n/a
 
      26th Oct 2007
dan,
For completeness' sake, are you using something like this?

Sub GetCustomRange()
Dim MyRangeRef As Range
On Error GoTo Select_Cncled
Set MyRangeRef = Application.InputBox("Select the range of cells",
"Reference?", , , , , , 8)
Exit Sub
Select_Cncled:
MsgBox "you cancelled the previous message, you naughty!"
End Sub

I'm not sure that there is a way to catch the "The formula you typed
contains an error" issue - since it does not seem to be an error that
fires an event back to VBA; it's simply a warning to the end user,
sort of saying, "Give me something to work with before you press OK,
dummy!" :-)
Error 424, on the other hand, is generated because upon pressing
Cancel, the input box is destroyed and the above code does not assign
the expected object to MyRangeRef; therefore, VBA complains by raising
a catchable error, to which the error handles courteously responds.

Learning something new every day,
-Basilisk96

On Oct 25, 8:27 pm, dan dungan <stagerob...@yahoo.com> wrote:
> Sorry I sent the last message before I was finished typing.
>
> Anyway, If I choose the cancel button, the procedure returns runtime
> error 424--object required.
>
> Also, I could never get the procedure to go to the error handler.
>
> Please help me understand the error handling.
>
> Thanks,
>
> Dan


 
Reply With Quote
 
papou
Guest
Posts: n/a
 
      26th Oct 2007
Hello dan
If you do not give the expected value (Cell reference) and choose OK , the
input box method will still show with a Excel error message indicating a
wrong input. This is a specific behaviour attached to the
Application.Inputbox method (different from the Inputbox function)
See help on Inputbox method for further information.

The error handler is valid (and functional) if you choose the Cancel button
with the sample code supplied.

HTH
Cordially
Pascal

"dan dungan" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
> Sorry I sent the last message before I was finished typing.
>
> Anyway, If I choose the cancel button, the procedure returns runtime
> error 424--object required.
>
> Also, I could never get the procedure to go to the error handler.
>
> Please help me understand the error handling.
>
> Thanks,
>
> Dan
>



 
Reply With Quote
 
dan dungan
Guest
Posts: n/a
 
      26th Oct 2007
Hi Pascal,

I don't know what I'm doing that causes the procedure not to return
the Select_Cncled error message.

I copied the procedure to the sheet3 module and I run the macro from
the tools/macro menu.

When I click on the Cancel button the procedure returns the Visual
Basic Debug message box showing run time error '424'.

Here's what is in the module:
Sub Test2()


Dim MyRangeRef As Range
On Error GoTo Select_Cncled

Set MyRangeRef = Application.InputBox("Select the range of cells",
"Reference?", , , , , , 8)
MsgBox MyRangeRef.Cells.Count
'do other stuff
'etc.
Exit Sub

Select_Cncled:
MsgBox "you cancelled the previous message, you naughty!"
End Sub


> The error handler is valid (and functional) if you choose the Cancel button
> with the sample code supplied.
>
> HTH
> Cordially
> Pascal
>


 
Reply With Quote
 
papou
Guest
Posts: n/a
 
      30th Oct 2007
Hi dan
The code would be better placed in a standard module.
But even if placed in a sheet module there should be no reason for its not
working.
Just tested on my version (Excel 2003)

HTH
Cordially
Pascal

"dan dungan" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
> Hi Pascal,
>
> I don't know what I'm doing that causes the procedure not to return
> the Select_Cncled error message.
>
> I copied the procedure to the sheet3 module and I run the macro from
> the tools/macro menu.
>
> When I click on the Cancel button the procedure returns the Visual
> Basic Debug message box showing run time error '424'.
>
> Here's what is in the module:
> Sub Test2()
>
>
> Dim MyRangeRef As Range
> On Error GoTo Select_Cncled
>
> Set MyRangeRef = Application.InputBox("Select the range of cells",
> "Reference?", , , , , , 8)
> MsgBox MyRangeRef.Cells.Count
> 'do other stuff
> 'etc.
> Exit Sub
>
> Select_Cncled:
> MsgBox "you cancelled the previous message, you naughty!"
> End Sub
>
>
>> The error handler is valid (and functional) if you choose the Cancel
>> button
>> with the sample code supplied.
>>
>> HTH
>> Cordially
>> Pascal
>>

>



 
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
How do I select a range of cells in an Excel table using the mouse jlethco_texas Microsoft Excel Misc 1 12th Apr 2010 11:23 PM
Not able to select range of cells with mouse. jen Microsoft Excel New Users 2 16th Sep 2009 06:21 PM
Cannot select single cell. Mouse move automatically creates range. =?Utf-8?B?RGF2ZSBKb25lcyAtIEVuZ2xhbmQ=?= Microsoft Excel Misc 1 22nd Apr 2007 09:37 AM
Code to Select a Combobox with having to Manually Mouse or Tab to enter a value Coza Microsoft Excel Programming 2 20th Mar 2007 08:21 AM
Mouse sticks in select range mode =?Utf-8?B?TmF1Z2h0eU1vdXNl?= Microsoft Excel Misc 8 6th Nov 2005 01:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 AM.