Consulting

Results 1 to 3 of 3

Thread: Need help figuring this code out!

  1. #1
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    1
    Location

    Need help figuring this code out!

    Hello I am trying to figure out how to make the following code work. I want to have users be able to create their own list to keep track of issues, and when they choose the issue it will auto fill the textboxs for them.

    Sub OpenForm()
    UserForm1.Show
    UserForm1.ComboBox1.SetFocus
    End Sub


    Private Sub UserForm_Initialize()
    Dim xRg As Range
        Set xRg = Worksheets("Sheet2").Range("A2:F1000")
        ComboBox1.List = xRg.Columns(1).Value
        ComboBox6.AddItem "Associate"
        ComboBox6.AddItem "Contactor"
        ComboBox6.AddItem "Vendor"
        ComboBox7.AddItem "EST"
        ComboBox7.AddItem "PST"
        ComboBox7.AddItem "CST"
        ComboBox7.AddItem "MST"
        ComboBox7.AddItem "AST"
        ComboBox7.AddItem "AKST"
        ComboBox7.AddItem "IST"
    End Sub

    Private Sub ComboBox1_Change()
        TextBox1.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, [xRg], 2)
        TextBox20.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 4, False)
        TextBox21.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 3, False)
        TextBox22.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 5, False)
        TextBox23.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 6, False)
    End Sub
    Last edited by Paul_Hossler; 07-08-2018 at 09:48 AM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I added CODE tags to your macros to format and set them off -- you can use the [#] icon to insert a pair and paste your macro in between them the next time

    You didn't say what is not working nor attach a sample workbook showing the issue, so this is just a guess

    TextBox1.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 2, False)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Another guess move this line
    Dim xRg As Range
    to the very top of the module, before any code

Posting Permissions

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