Selection as String

S

Shakespear

Hi.

I have created a macro in Excel which have a Form. The form contain
among other things a RefEdit. When I launch the macro this RefEdit i
empty, but I want it to contain for example Sheet1!$F$2:$F$9 as th
default value if these cells are selected in the active sheet.

So what I need to know is if there is a way to get the selecte
range/cell(s) as a string representation.

Pseudo code:
-----------------------------

Code
-------------------

Public Sub MyMacro()
Dim MyRefString As String

' Start of getting Selection as String-->
MyRefString = ...
'<-- End of getting Selection as String

With MyForm
.MyRefEdit.Value = MyRefString
End With
...
End Sub
 
B

Bernie Deitrick

Jörgen,

UserForm1.RefEdit1.Text = Range("F2:F9").Address(True, True, xlA1, True)

Using your object names:

MyRefString = Range("F2:F9").Address(True, True, xlA1, True)
MyForm.MyRefEdit.Text = MyRefString

HTH,
Bernie
MS Excel MVP
 
B

Bernie Deitrick

Sorry, missed the part about using the current selection:

MyRefString = Selection.Address(True, True, xlA1, True)
MyForm.MyRefEdit.Text = MyRefString

HTH,
Bernie
MS Excel MVP


Bernie Deitrick said:
Jörgen,

UserForm1.RefEdit1.Text = Range("F2:F9").Address(True, True, xlA1, True)

Using your object names:

MyRefString = Range("F2:F9").Address(True, True, xlA1, True)
MyForm.MyRefEdit.Text = MyRefString

HTH,
Bernie
MS Excel MVP
 

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