In a Userform, Link Textbox to the same row as the

2019-08-17 06:13发布

问题:

I have created a userform with 2 comboboxes, a textbox and a button that will link the comboboxes/textbox depending on the scenario.

For one of the scenarios, if combobox 2, displays the same text/value currently in the worksheet MRFGLR Range Column A change the value of column AE with the textbox value in the same row as the combobox 2 value in Worksheet MFGLR. In a Userform, Link Textbox to the same row as the combobox but different Column

I'm having trouble having the code find the same row as combobox2 value and then pasting the textbox1 value 31 columns to the right as that. This is what I have so far.

With Worksheets("MFGLR").Range("a1:a500")
Set C = .Find(ComboBox2.Value, LookIn:=xlValues)
If Not C Is Nothing Then
    firstAddress = C.Address
    Do
        C.Value = TextBox1.Value
        Set C = .FindNext(C)
    Loop While Not C Is Nothing
End If
End With

回答1:

One way to find which row you need based on the value in "combobox2" would be to use the Range.Find Method. Here is the documentation from Microsoft on how to use the method. You would pass in the value in "combobox2" as the value to find. It also shows you how to catch an error when you don't find the value you are looking for (which in my experience can happen quite often).

The Range.Find method returns a Range Object, which is basically an address for a cell. From there you could use something like .Row to find the row you need and then reference it in combination with your column "AE".

Let me know if this helps! Good Luck!