我想写一个Vlookup语句。我正在使用一系列以下内容填充 VBA 表单中的文本框:
与 frmDragonInfo
.txtInfo6 = Application.Text(WorksheetFunction.VLookup(DrLevel + 1, Range(DrCode), 2), "[hh]:mm")
然后,更新文本框后,我想单击表单上的cmd按钮,再次将其写回:
带表格("数据列表")
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 以获得完全匹配?(VLOOKUP功能)
使用.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