Problems with embedded RefEdit control on worksheet

Kelvin Stott

Active Member
Joined
Oct 26, 2010
Messages
338
Hi,

I have embedded a RefEdit control directly in a worksheet, but it doesn't seem to work. Essentially I would like the user to select a range, or ranges, so that the program can store the address in a linked cell. However, the control doesn't seem to take in the selected range. I have tried toggling different combinations of the control's properties, but still no luck...

Any thoughts on how to fix this, please?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do I need to do something with this?

Private Sub DRange1_BeforeDragOver(Cancel As Boolean, ByVal Data As MSForms.DataObject, _
ByVal x As stdole.OLE_XPOS_CONTAINER, ByVal y As stdole.OLE_YPOS_CONTAINER, _
ByVal DragState As MSForms.fmDragState, Effect As MSForms.fmDropEffect, ByVal Shift As Integer)

DRange1.Value = Selection.Address 'Just a guess at entering something to make it work...

End Sub
 
Upvote 0
Having read through a number of similar posts without resolution, I'm starting to give up on this approach, so...

Is there any other (simple) way to get the address of a user-selected range into a cell, without creating a user form?
 
Upvote 0
It looks like the RefEdit control doesn't have the same functionality on the worksheet as it does on a UserForm. Maybe the Input method of the Application object can be used instead. The following macro displays an input box and allows the user to select a range. If the user chooses one, it enters its address in the specified cell. If the user cancels, it exits the sub.

Code:
[FONT=Courier New][COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR]
[COLOR=darkblue]Sub[/COLOR] test()
    [COLOR=darkblue]Dim[/COLOR] UserSel [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
    [COLOR=darkblue]Set[/COLOR] UserSel = Application.InputBox( _
        Prompt:="Please select a cell or range of cells...", _
        Title:="Range Selection", _
        Type:=8)
    [COLOR=darkblue]If[/COLOR] UserSel [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
    
    Worksheets("Sheet2").Range("A2").Value = UserSel.Address [COLOR=#008000]'change the sheet name and cell reference accordingly[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
[/FONT]
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top