In a Userform, Link Textbox to the same row as the combobox but different Column

两盒软妹~` 提交于 2019-12-13 05:42:56

问题


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!



来源:https://stackoverflow.com/questions/56367391/in-a-userform-link-textbox-to-the-same-row-as-the-combobox-but-different-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!