Consulting

Results 1 to 6 of 6

Thread: Solved: values in range

  1. #1

    Solved: values in range

    I have a combox that I want to put the values in sheet1 but if I put C30 it will appear many blanks
    And it as to be dinamic so the user inputs something and vba find the cells with content and put tehm in the combo list.
    If I can understand I adapt to my file


    File attached

    Thanks in advanced
    Attached Files Attached Files

  2. #2
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    fgarcia90,
    Try using the following code in the UserForm_Activate()...

    [VBA]Private Sub UserForm_Activate()
    Dim i As Integer

    'UserForm1.ComboBox1 = Sheet1.Range("C2:C30").Value
    For i = 2 To 30
    If Sheet1.Cells(i, 3) <> "" Then UserForm1.ComboBox1.AddItem (Sheet1.Cells(i, 3))
    Next i

    End Sub[/VBA]

  3. #3
    Thanks Ninja.
    But do you know how to replace the value of 30, and making vba search the last row in that collum with content to add to the combo?
    And another thing... doesn't should appear somewhere in the code the collum "C"?
    Is it the ",3"?
    I'm new in vba :-)

    Last edited by fgarcia90; 07-16-2012 at 11:52 AM.

  4. #4
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    use sheet1.range("C65536").end(xlup).row instead of 30... so...

    [VBA]Private Sub UserForm_Activate()
    Dim i As Integer

    'UserForm1.ComboBox1 = Sheet1.Range("C2:C30").Value
    For i = 2 To Sheet1.Range("C65536").End(xlUp).Row
    If Sheet1.Cells(i, 3) <> "" Then UserForm1.ComboBox1.AddItem (Sheet1.Cells(i, 3))
    Next i

    End Sub[/VBA]

  5. #5
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    try this example attached
    Attached Files Attached Files

  6. #6
    Rob342, Ninja code works but yours simpler, but where is "mycode"?

    oh yeah, just saw, in name manager

    thanks both

Posting Permissions

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