我想写一个Vlookup语句

我想写一个Vlookup语句。 我正在用一系列的VBA格式填充文本框:

用frmDragonInfo

.txtInfo6 = Application.Text(WorksheetFunction.VLookup(DrLevel + 1, Range(DrCode), 2), "[hh]:mm") 

然后,更新了文本框,我想单击表单上的cmdbutton,然后再次写回:

使用表格(“DataList”)

 Application.WorksheetFunction.VLookup(DrLevel, Range(DrCode), 2) = txtInfo1.Text 

DrLevel是从1到100的数字,DrCode是“DataList”表单上的一个命名范围。 这是行不通的。 我可以写一个Vlookup吗? 如果是的话,怎么样? 谢谢。

 Dim f As Range Set f = Sheets("DataList").Range(DrCode).find(DrLevel, lookat:=xlWhole) If Not f Is Nothing Then f.Offset(0,1).Value = txtInfo1.Text End If 

你不必依赖于所有的工作表函数。 VBA有自己的Application.Text版本。

 .txtInfo6 = Format(WorksheetFunction.VLookup(DrLevel + 1, Range(DrCode), 2), "[hh]:mm") 

应该有(可选) range_lookup参数设置为False完全匹配? ( VLOOKUPfunction )

使用.Columns(1)切断Range(DrCode)的第一列并向后看。

 dim rw as long rw = application.match(DrLevel + 1, Range(DrCode).Columns(1), 0) Range(DrCode).cells(rw, 2) = txtInfo1.Text