+ Reply to Thread
Results 1 to 3 of 3

Populate textbox from multiple combobox entries

Hybrid View

  1. #1
    Registered User
    Join Date
    02-06-2013
    Location
    Sheffield
    MS-Off Ver
    2007
    Posts
    32

    Populate textbox from multiple combobox entries

    I have a table of dates, stores and contacts for a lookup of who to call on what day.

    Date Store1 Store2 Store3
    07/10 Bob John Gary
    08/10 Bob Ryan Gary
    09/10 Mike Phil Ian

    I'd like to have 2 combo boxes, 1 listing the dates and the other listing the stores with a text box returning the name of who to call.

    I can get it to work to a point if I specify the column to check but can't figure out how to specify the range using the 2nd combo box.

    Private Sub ComboBox1_Change()
    TextBox1.Value = Range("B" & ComboBox1.ListIndex + 1)
    End Sub
    As a side not my Combobox shows the dates correctly as '07/10/2014' until selected which then showing as a general number '41919'

    Cheers

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Populate textbox from multiple combobox entries

    Try using the Cells object instead of the Range object.

    Private Sub ComboBox1_Change()
        If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
            TextBox1.Value = Cells(ComboBox1.ListIndex + 1, ComboBox2.ListIndex + 1)
        Else
            TextBox1.Value = ""
        End If
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    02-06-2013
    Location
    Sheffield
    MS-Off Ver
    2007
    Posts
    32

    Re: Populate textbox from multiple combobox entries

    Quote Originally Posted by AlphaFrog View Post
    Try using the Cells object instead of the Range object.

    Private Sub ComboBox1_Change()
        If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
            TextBox1.Value = Cells(ComboBox1.ListIndex + 1, ComboBox2.ListIndex + 1)
        Else
            TextBox1.Value = ""
        End If
    End Sub
    Cheers AlphaFrog,

    With just a little tweak changing to +2 it works perfectly.

    I'll have a play with the date function now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Pre-populate TextBox with cell entries for each row
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-19-2014, 09:18 AM
  2. Populate textbox based off ComboBox Selection
    By ladams41 in forum Excel General
    Replies: 1
    Last Post: 04-09-2014, 10:13 AM
  3. [SOLVED] Excel Userform: Populate other controls (i.e. textbox & combobox) based on combobox select
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 04:50 PM
  4. Populate textbox from a combobox (Solved)
    By age in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-02-2012, 07:14 AM
  5. Combobox populate textbox
    By samtwilliams in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2007, 10:27 AM

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