在Userform中获取值以搜索参考编号

时间:2017-04-17 18:42:18

标签: database vba excel-vba userform excel

您好我希望使用userform从表中的特定行返回值。我通过调整代码来更新值和思想取得了一些成功,我可以通过调整代码将相反的值拉回到用户窗体中。如果有人可以提供帮助,我会非常感激。

Private Sub Find_Click()

Dim searchRange As Range
Dim foundCell As Range
Dim mysearch As String

mysearch = Me.Search.Value

With ThisWorkbook.Sheets("Master Data")
    Set searchRange = .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
End With

Set foundCell = searchRange.Find(what:=mysearch, Lookat:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not foundCell Is Nothing Then
    Me.MerchInstall.Value = foundCell.Offset(0, 7).Value
    Me.ReOrderCode.Value = foundCell.Offset(0, 13).Value
Else
     MsgBox "ID does not exist."
End If

End Sub

谢谢,

0 个答案:

没有答案