Selecting a cell during a macro

S

Sue

Selecting a cell during a macro
I want the user to be able to use the mouse to click on the position for the
rest of the macro to run.
A form asks the user to select the correct position. At present I have this
done by getting the row number typed in to the form (or the number of rows up
or down to move). This is rather awkward and old-fashioned and I would like
the form just to tell the user to click on the required position.
 
P

Paul

Sue,

Not sure if this is the answer your looking for but,

Load your user form as vbModeless; so Userform.show vbModeless, then you can
click anywhere on the sheet you want to. Then make sure that your macro runs
on the activecell.

Cheers,

Paul
 
P

paul.robinson

Sue,

Not sure if this is the answer your looking for but,

Load your user form as vbModeless; so Userform.show vbModeless, then you can
click anywhere on the sheet you want to. Then make sure that your macro runs
on the activecell.

Cheers,

Paul





- Show quoted text -

Hi
Two ways:

1. Put a RefEdit control on your userform. This is available from the
Toolbox when creating a Userform. It is the one which allows the user
to select a Range with the mouse.
Then
Set myRange = Userform1.myRefEditControl.Value
If not myRange is nothing then
'code using myRange
End if
2. If you don't have a userform use the Application inputbox

Set myRange = Application.Inputbox("Please Select a Range with the
Mouse", Type:=8)
If not myRange is nothing then
'code using myRange
End if

This will display the inputbox with an OK and Cancel Button. If Cancel
is clicked then myRange is Nothing. The Type 8 setting is for a Range
as input.

regards
Paul
 
P

Patrick Molloy

the application.inputbox does exactly what you need...


Sub text_this()

Dim rChosen As Range

Set rChosen = Application.InputBox("Select a cell or range", Type:=8)

rChosen.Interior.Color = vbBlue

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top