[英]VBA Excel - Show row data in the UserForm based on the ID
I'm currently working with an UserForm with an UPDATE function.我目前正在使用带有 UPDATE function 的用户窗体。 I just want to ask if how can I show the value in my UserForm?
我只想问我如何在我的用户窗体中显示值? As of now, I only accomplished it by using the code below.
到目前为止,我只是通过使用下面的代码来完成它。
txtBox_ID.Text = CStr(ThisWorkbook.Sheets("Results").Range("D7").Value)
txtBox_lname.Text = CStr(ThisWorkbook.Sheets("Results").Range("D8").Value)
txtBox_fname.Text = CStr(ThisWorkbook.Sheets("Results").Range("D9").Value)
txtBox_mname.Text = CStr(ThisWorkbook.Sheets("Results").Range("J8").Value)
txtBox_ext.Text = CStr(ThisWorkbook.Sheets("Results").Range("J9").Value)
As you can see the data is coming from Results sheet, but I want the UserForm to get the data in the Data sheet in which all the other data are located since I think it is needed in the find and update process.如您所见,数据来自结果表,但我希望用户窗体获取所有其他数据所在的数据表中的数据,因为我认为在查找和更新过程中需要它。
Here's the sample file so you can understand better.这是示例文件,以便您更好地理解。 I'm just a newbie in this VBA thing and sorry for the poor English.
我只是这个 VBA 事情的新手,很抱歉英语不好。
This seems to work on my worksheet.这似乎适用于我的工作表。
Private Sub UserForm_Initialize()
Set ws = ActiveWorkbook.Worksheets("Data")
lastrow = ws.Cells(Rows.Count, "C").End(xlUp).Row
For r = 10 To lastrow
If ws.Cells(r, 3) = CStr(ThisWorkbook.Sheets("Results").Range("D7").Value) Then
txtBox_ID.Text = ws.Cells(r, 3).Value
txtBox_lname.Text = ws.Cells(r, 4).Value
txtBox_fname.Text = ws.Cells(r, 5).Value
txtBox_ext.Text = ws.Cells(r, 6).Value
txtBox_mname.Text = ws.Cells(r, 7).Value
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.