ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selection as String (https://www.excelbanter.com/excel-programming/336499-selection-string.html)

Shakespear

Selection as String
 

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

-------------------

-------------------------------

Any ideas?

/Jörge

--
Shakespea
-----------------------------------------------------------------------
Shakespear's Profile: http://www.excelforum.com/member.php...fo&userid=2595
View this thread: http://www.excelforum.com/showthread.php?threadid=39328


K Dales[_2_]

Selection as String
 
ActiveSheet.Name & "!" & Selection.Address
--
- K Dales


"Shakespear" wrote:


Hi.

I have created a macro in Excel which have a Form. The form contains
among other things a RefEdit. When I launch the macro this RefEdit is
empty, but I want it to contain for example Sheet1!$F$2:$F$9 as the
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 selected
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

--------------------

-------------------------------

Any ideas?

/Jörgen


--
Shakespear
------------------------------------------------------------------------
Shakespear's Profile: http://www.excelforum.com/member.php...o&userid=25957
View this thread: http://www.excelforum.com/showthread...hreadid=393283



Bernie Deitrick

Selection as String
 
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


"Shakespear" wrote in message
...

Hi.

I have created a macro in Excel which have a Form. The form contains
among other things a RefEdit. When I launch the macro this RefEdit is
empty, but I want it to contain for example Sheet1!$F$2:$F$9 as the
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 selected
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

--------------------

-------------------------------

Any ideas?

/Jörgen


--
Shakespear
------------------------------------------------------------------------
Shakespear's Profile: http://www.excelforum.com/member.php...o&userid=25957
View this thread: http://www.excelforum.com/showthread...hreadid=393283




Bernie Deitrick

Selection as String
 
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" <deitbe @ consumer dot org wrote in message
...
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


"Shakespear" wrote in message
...

Hi.

I have created a macro in Excel which have a Form. The form contains
among other things a RefEdit. When I launch the macro this RefEdit is
empty, but I want it to contain for example Sheet1!$F$2:$F$9 as the
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 selected
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

--------------------

-------------------------------

Any ideas?

/Jörgen


--
Shakespear
------------------------------------------------------------------------
Shakespear's Profile: http://www.excelforum.com/member.php...o&userid=25957
View this thread: http://www.excelforum.com/showthread...hreadid=393283






Shakespear[_2_]

Selection as String
 

Thanks!

I'll try it when I get back to work at monday

--
Shakespea
-----------------------------------------------------------------------
Shakespear's Profile: http://www.excelforum.com/member.php...fo&userid=2595
View this thread: http://www.excelforum.com/showthread.php?threadid=39328



All times are GMT +1. The time now is 05:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com