+ Reply to Thread
Results 1 to 5 of 5

With Selection Input Cell Value or Range into User Form

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    With Selection Input Cell Value or Range into User Form

    Hi all,

    I'm trying to setup some code that, if a user selects a specific cell then that cell value will
    be inputed into a user form. I tried reversing some code that I have that adds a users
    cell range selection to cell, but something is still not right.

    Here's what I have thus far:

     Dim Raddress As Range, strAddress As String
     With Selection
     Set Raddress = Cells(17, 3).Value
     UserForm1.RefEdit1.Text = Raddress.Address 'Allow cell selection to be placed into user form
     Raddress.Address = UserForm1.RefEdit1.Text 'Allow changes to the range be made also in  the userform field.
     
     End Select
      ' Set Raddress = Application.InputBox("Select your range to print by placing your mouse pointer over a starting cell box. Left click and hold while moving your pointer to the last desired cell. Then choose OK to Print or Cancel to Stop.", Type:=8)
         '17 = Rows  ,15= Columns
        'Raddress = Raddress.Address
    Set Raddress = Range(Cells(17, 3).Value) '17 = Rows  ,3= Columns C' Places last entered value in userform field back into selected cell.
    Any help is appreciated.
    Thanks,

    BDB
    Last edited by bdb1974; 03-04-2010 at 05:37 PM.

  2. #2
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: With Selection Input Cell Value or Range into User Form

    ...Just an added explanation. Currently when I click in a cell, will add the
    Cell Address ,

    For instance, clicking on C17, puts "$C$17" into my userform.

    I need the cells value added to the userform.

    So if the value in C17 = "MYNAME" then "MYNAME" will be put into the userform.


    HTH's.

    BDB

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: With Selection Input Cell Value or Range into User Form

    Hi all, I found the following at http://http://www.erlandsendata.no/e...tboxfillunique

    
    Fill a ListBox with unique values from a worksheet 
    The example macros below shows how you can fill a ListBox-control (and a ComboBox-control) in a UserForm with the unique values from worksheet range. Copy the code to the UserForm code module. 
    
    Private Sub UserForm_Initialize()
    Dim MyUniqueList As Variant, i As Long
        With Me.ListBox1
            .Clear ' clear the listbox content
            MyUniqueList = UniqueItemList(Range("A4:A100"), True)
            For i = 1 To UBound(MyUniqueList)
                .AddItem MyUniqueList(i)
            Next i
            .ListIndex = 0 ' select the first item
        End With
    End Sub
    
    
    Private Function UniqueItemList(InputRange As Range, _
        HorizontalList As Boolean) As Variant
    Dim cl As Range, cUnique As New Collection, i As Long, uList() As Variant
        Application.Volatile
        On Error Resume Next
        For Each cl In InputRange
            If cl.Formula <> "" Then
                cUnique.Add cl.Value, CStr(cl.Value)
            End If
        Next cl
        UniqueItemList = ""
        If cUnique.Count > 0 Then
            ReDim uList(1 To cUnique.Count)
            For i = 1 To cUnique.Count
                uList(i) = cUnique(i)
            Next i
            UniqueItemList = uList
            If Not HorizontalList Then
                UniqueItemList = _
                    Application.WorksheetFunction.Transpose(UniqueItemList)
            End If
        End If
        On Error GoTo 0
    End Function
    I was hoping that I could incorporate this into my userform using refedit,
    I'm put together this:


    Private Sub CommandButton2_Click()
    Dim path As String
    Dim Rng As Range
    Dim addr As Range
    Dim Raddress As Range, strAddress As String
    Dim MyUniqueList As Variant, i As Long
    Dim stPath As String
    
    stPath = "L:\Elec Dept Projects\RELEASED FOR CONSTRUCTION\" & Sheets("BOM").Range("C6").Value & " " & Sheets("BOM").Range("C7").Value & " " & "-" & " " & Sheets("BOM").Range("C8").Value & "\"
    If Sheets("BOM").Range("C18") <> " " And Sheets("BOM").Range("C8") <> " " Then
    path = Sheets("BOM").Range("C18").Value & "\" & Sheets("BOM").Range("C6").Value & "_BOM_Revised.htm"
    Else
    path = stPath & Sheets("BOM").Range("C6").Value & "_BOM_Revised.htm"
    End If
     With Me.UserForm1.RefEdit1.Text
      .Clear
      MyUniqueList = UniqueItemList(Range("C17:C17"), True)
      .AddItem MyUniqueList(MyUniqueList)
       .ListIndex = 0 ' select the first item
        End With
     
    Set Raddress = MyUniqueList
    .....end of code of interest.
    Using it with the Function Code, I'm get the same result. Bascially back to square 1.
    ... I wouldn't think it should be so difficult getting the the cell value place into a userform box by selecting a cell manually or with code.

    Again any input is greatly appreciated.

    BDB

  4. #4
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: With Selection Input Cell Value or Range into User Form

    If possible,

    Can someone provide any type of an example of adding a cell value into a userform by "clicking" & making a cell active or making an cell active/select through code?

    Thanks,

    BDB
    Last edited by bdb1974; 03-03-2010 at 03:16 PM.

  5. #5
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: With Selection Input Cell Value or Range into User Form

    Alrighty guys and gals,

    I have finally put together some code that's working for me.
    In case your interested, I've atached an example booklet w/code.


    I think this is pretty cool. Hopefully you will too.

    Regards,

    BDB
    Attached Files Attached Files

+ 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