+ Reply to Thread
Results 1 to 13 of 13

UserForm Combobox code to show offset from sheet...2013

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    UserForm Combobox code to show offset from sheet...2013

    Good day,
    I can't wrap my head around this issue. I have a userform with the following code:

    Private Sub UserForm_Initialize()
        Caption = "Selection"
        Me.ComboBox1.Clear
        LastRow = Worksheets("Standart Control").Range("A2").End(xlDown).Row
        ComboBox1.List = Worksheets("Standart Control").Range("A2:A" & LastRow).Value
    End Sub
    I need to add the following and thought it would be easy but can't figure it out...On my Worksheets("Standart Control") I have 2 column, both starting at A2 and the other B2. The two rows are meant to be together. One row is for my titles and each titles as a code beside them.

    I have a TextBox3 in my userform right beside my combobox. I need that when I select the desired text from my combobox to add the code TextBox3 so if A6 in my is selected the B6 must show in my TextBox3. The reason I do not do a Range is because in my sheet I will always have additional information to add to this column.

    Also I need it to be vice versa... If the code is in my TextBox3 then to populate the info in my Combobox1...


    Could someone help me?

    Excelnoub

  2. #2
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    I have attached a workbook just in case...

    Userform.xlsm

    Instructions are on Sheet2

    Hope this helps :S

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: UserForm Combobox code to show offset from sheet...2013

    Try this.
    Private Sub ComboBox1_Change()
        TextBox1.Value = ComboBox1.Value
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim LastRow As Long
    
        Caption = "Selection"
        LastRow = Worksheets("Sheet2").Range("A2").End(xlDown).Row
        ComboBox1.List = Worksheets("Sheet2").Range("A2:B" & LastRow).Value
        ComboBox1.BoundColumn = 2
    
    End Sub
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    Perfect :D

    Thank you so much Norie... I will figure out the reverse step you have given me more then enough

    ExcelNoub

  5. #5
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    Trying to add the reverse to it with no luck

    If the user adds info in the textbox then to select the same in the combobox. I tried to make a reverse code with no luck...

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Why do you need the reverse?

  7. #7
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    The information that shall be inserted in my "Range" and "Code" is confidential. But there will be people with no knowledge of the title and will base this list on the Code (Column B) and others only on the List ot title (Column A).

    If a user doesn't know that title (Column A) then he will insert the Code in Textbox1 but I need to have the combobox populate the same way around.

    Is there a way to do this?

    So if 1 is inserted in the Textbox1 to = column A and 1 is text1 so Test1 will be inserted in Combobox1.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    You could display both columns in the combobox.

  9. #9
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    Yes very true,
    but in this case I have 100 Titles with different codes and will be adding probably 100 more within the year therefore...

    If
    A5 = Test5 and the code is 937 but
    A4 = Test4 and the code is 3

    it will be confusion to find the code in 100 + Title...I am just trying to make it less complicated for the user.

    Guess I could make a selection to the user to choose either by title or by code

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    You could have 2 comboboxes, one for code and one for description.

    They could be tied together via code so that they synchronize.

    For example, when the user selects a description from the one of the comboboxes the corresponding code/description is automatically selected in the other.

  11. #11
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    Well in that case... I would love to make that change to 2 comboboxes...

    There they could change one or the other... Sign* tried to do that with the code you gave me by kind of duplicating the code and trying to offest the boundcolumn but was getting an error.

  12. #12
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    LOL how do I offset my Combobox2?

    Trying to use the same code

    Dim LastRow1, LastRow2 As Long
    
    Private Sub UserForm_Initialize()
        Caption = "Selection"
        
        LastRow1 = Worksheets("Sheet2").Range("A2").End(xlDown).Row
        ComboBox1.List = Worksheets("Sheet2").Range("A2:B" & LastRow1).Value
        ComboBox1.BoundColumn = 2
        
        LastRow2 = Worksheets("Sheet2").Range("B2").End(xlDown).Row
        ComboBox2.List = Worksheets("Sheet2").Range("B2:B" & LastRow2).Value ' What will B2:??? become
    '    ComboBox2.BoundColumn = 2 'how do I offset the BoundColumn to look in A?
    
    
    End Sub
    
    Private Sub ComboBox1_Change()
        ComboBox2.Value = ComboBox1.Value
    End Sub
    
    Private Sub ComboBox2_Change()
    
    End Sub

  13. #13
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox code to show offset from sheet...2013

    Final Code:

    Dim LastRow1, LastRow2 As Integer
    Private Sub UserForm_Initialize()
        Caption = "Selection"
        Me.ComboBox1.Clear
        LastRow1 = Worksheets("Sheet2").Range("A2").End(xlDown).Row
        ComboBox1.List = Worksheets("Sheet2").Range("A2:A" & LastRow1).Value
         
        Me.ComboBox2.Clear
        LastRow2 = Worksheets("Sheet2").Range("B2").End(xlDown).Row
        ComboBox2.List = Worksheets("Sheet2").Range("B2:B" & LastRow2).Value
    End Sub
    
    Private Sub ComboBox1_Change()
        Me.ComboBox2.ListIndex = Me.ComboBox1.ListIndex
    End Sub
     
    Private Sub ComboBox2_Change()
        Me.ComboBox1.ListIndex = Me.ComboBox2.ListIndex
    End Sub
    Thank you for everything :D

+ 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. userform combobox to show current month
    By losmi8 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2014, 04:45 AM
  2. [SOLVED] Stuck using the Offset in Excel 2013, hi guys and gals, what is wrong with this code?
    By Hurricanefly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2013, 01:01 PM
  3. Show UserForm from ComboBox
    By sgp in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-17-2011, 08:48 AM
  4. Userform Combobox - Show 2 columns Use data from 2nd Column
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2011, 03:26 PM
  5. Obtaining an offset value from a userform combobox
    By kanuvas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2008, 12:43 PM

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