我目前在我的VBA
代码中有以下行Inputbox
:
Set myValues = Application.InputBox("Please select on the spreadsheet the first cell in the column with the values that you are looking for:", Type:=8)
但是,当我选择单元格时,它会自动输入例如$A$1
. 可以更改此设置,而无需用户手动删除 $,以便Inputbox
自动将单元格引用设为A1
?
它是自动VLookup
宏的一部分,除了VLookup
在整个列中固定值之外,它可以完美地工作。
提前致谢。
更新 - 这是完整的代码:
Dim FirstRow As Long
Dim FinalRow As Long
Dim myValues As Range
Dim myResults As Range
Dim myCount As Integer
Sub VlookupMacroNew()
Set myValues = Application.InputBox("Please select on the spreadsheet the first cell in the column with the values that you are looking for:", Default:=Range("A1").Address(0, 0), Type:=8)
Set myResults = Application.InputBox("Please select on the spreadsheet the first cell where you want your lookup results to start:", Type:=8)
myCount = Application.InputBox("Please enter the column number of the destination range:", Type:=1)
On Error Resume Next
myResults.EntireColumn.Insert Shift:=xlToRight
Set myResults = myResults.Offset(, -1)
FirstRow = myValues.Row
FinalRow = Cells(65536, myValues.Column).End(xlUp).Row
Range(myResults, myResults.Offset(FinalRow - FirstRow)).Formula = _
"=VLOOKUP(" & Cells(FirstRow, myValues.Column).Address & ", " & _
"'S:\Payroll\CONTROL SECTION\[Latest Data.xls]Sheet1'!$A$1:$B$100" & ", " & myCount & ", False)"
myValues 将从单元格 A2 开始,但是当我们使用动态列表时,我需要将查找值更改为 A3、A4、A5 等,因为公式被复制到列表中。通过使用 $A$2 的输入框,查找公式仅查看该单元格引用。