+ Reply to Thread
Results 1 to 5 of 5

Selection as String

  1. #1
    Registered User
    Join Date
    08-05-2005
    Posts
    2

    Selection as String

    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:
    -----------------------------
    Please Login or Register  to view this content.
    -------------------------------

    Any ideas?

    /Jörgen

  2. #2
    K Dales
    Guest

    RE: 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
    >
    >


  3. #3
    Bernie Deitrick
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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
    >




  4. #4
    Bernie Deitrick
    Guest

    Re: 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
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > news:[email protected]...
    >>
    >> 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
    >>

    >
    >




  5. #5
    Registered User
    Join Date
    08-05-2005
    Posts
    2
    Thanks!

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1