私は現在、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を使用する入力ボックスでは、ルックアップ式はそのセル参照のみを調べます。