Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    UserForm:Update Sheet from 2 Combos (2003 SP2)

    Good morning

    I was looking at another forum and saw this unanswered questions that almost mirrors what I am trying to do, does anybody here have an idea of how to do this

    <font color=blue>I have a user form with 2 combos and a text box -

    Combo 1 takes its value from a range on a different WS
    Combo 2 takes its value from a horizontal range on the current WS (15 column headings B-O) Column A is left to take the info from Combo 1

    Take the info from Combo 1 and place in the first empty space in Column A (after A3)
    Take the info from Combo 2 and match it the (range) column heading in B to O and insert the numeric value entered into the correct cell.

    Staff ------------ Singapore -------- India -------- Philippines --------- Etc
    David ......................3
    Jenny ................................................4

    (FYI these are weeks of overseas postings)</font color=blue>

    Cheers

    Steve
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: UserForm:Update Sheet from 2 Combos (2003 SP2)

    Try code like this, substituting the correct names for the sheet where you want to enter the values, and of the combo boxes and text box:
    <code>
    Dim r As Long
    Dim c As Long
    Dim wsh As Worksheet
    Dim rng As Range

    Set wsh = Worksheets("MySheet")
    With wsh
    r = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
    .Cells(r, 1) = Me.ComboBox1
    Set rng = .Range("1:1").Find(What:=Me.ComboBox2, LookIn:=xlValues, LookAt:=xlWhole)
    If rng Is Nothing Then
    MsgBox "Can't find cell for " & Me.ComboBox2, vbExclamation
    Exit Sub
    End If
    c = rng.Column
    .Cells(r, c) = Me.TextBox1
    End With</code>

  3. #3
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm:Update Sheet from 2 Combos (2003 SP2)

    Thanks Hans

    2 questions

    1. For my purposes the Combos are cboCountry and cboPackingMaterial which I have changed in your example, when I run this code the Country finds the next blank row Ok and inserts the Country but it says it can't find a cell for whatever product that I select, my cboPackingMaterial takes its range form a horizontal range on the current worksheet, please see screen shot below, does the code need adjusting tio take this into account?

    2. Etiquette - should I post this answer to the forum where I saw the original question and credit Woody's lounge or is that not the done thing?

    Cheers

    Steve
    Attached Images Attached Images
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: UserForm:Update Sheet from 2 Combos (2003 SP2)

    1. I'd have to see the workbook to know what is wrong. The code works in a simple test.

    2. The problem hasn't been solved yet...

  5. #5
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm:Update Sheet from 2 Combos (2003 SP2)

    Editted: sorry I should have mentioned that the button/code in question is on the 'Add Stock' button

    Hi Hans

    Thanks as usual

    Please find attached my sample WorkBook

    Cheers

    Steve
    Attached Files Attached Files
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: UserForm:Update Sheet from 2 Combos (2003 SP2)

    You're searching row 1 but the headers are in row 2. Change this:
    <code>Set rng = .Range("1:1").Find(What:=Me.cboStock, LookIn:=xlValues, LookAt:=xlWhole)</code>
    to this:
    <code>Set rng = .Range("2:2").Find(What:=Me.cboStock, LookIn:=xlValues, LookAt:=xlWhole)</code>
    or use a named range for flexibility.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm:Update Sheet from 2 Combos (2003 SP2)

    Thanks Rory

    In hindsight and now you have pointed that out I realise that Hans intended me to change certain things to personalise it to my requirement, I had changed the combo and text box names but it never occured to me what the 1:1 was doing, it makes complete sense now

    Cheers

    Steve
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

Posting Permissions

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