あなたは
Dim rng As Range
With Sheets("CustomerList") '<--| reference "CustomerList" sheet
With .Range("A2", .Cells(.Rows.count, 1).End(xlUp)) '<--| reference its column A range from row 2 down to last not empty one
Set rng = .Find(what:=Range("C10").Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) '<--| search referenced range for "Cust Num" entry
If Not rng Is Nothing Then '<--| if found
Range("C11").Value = rng.Offset(, 1).Value '<--| fill cell C11 with value in cell 1 column offset the found CustNum
Range("C12").Value = rng.Offset(, 2).Value '<--| fill cell C12 with value in cell 2 columns offset the found CustNum
Range("I11").Value = rng.Offset(, 3).Value '<--| fill cell I11 with value in cell 3 columns offset the found CustNum
End If
End With
End With
さらに、私がすることを得たあなたのスクリーンショットからRange
オブジェクトのFind()
方法とオフより良いかもしれませんあなたは "フォーム"のsheeでユーザーのエントリを管理しようとしていますt。あなたはユーザーによって変更されたセルをチェックし、それに応じて
でそのセルの内容を処理するために、サブに対応する起動
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address(False, False)
Case "C10" '<--| user edited "Cust Num" entry
FillCustomerInfo Target.Value '<--| call the sub responsible for handling "Customer Number" entry
Case "C6" '<--| user edited "Order Number" entry
FillOrderNumberInfo Target.Value '<--| call the sub responsible for handling "Order Number" entry
Case Else
End Select
End Sub
:私は、このようなWorksheet_Change()
イベントハンドラを書いたと思います。この場合
この場合は、FillCustomerInfo()
サブしたがって、次のようになります。
Sub FillCustomerInfo(val As Variant)
Dim rng As Range
With Sheets("CustomerList") '<--| reference "CustomerList" sheet
With .Range("A2", .Cells(.Rows.count, 1).End(xlUp)) '<--| reference its column A range from row 2 down to last not empty one
Set rng = .Find(what:=val, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) '<--| search referenced range for passed value
If Not rng Is Nothing Then '<--| if found
Range("C11").Value = rng.Offset(, 1).Value '<--| fill cell C11 with value in cell 1 column offset the found CustNum
Range("C12").Value = rng.Offset(, 2).Value '<--| fill cell C12 with value in cell 2 columns offset the found CustNum
Range("I11").Value = rng.Offset(, 3).Value '<--| fill cell I11 with value in cell 3 columns offset the found CustNum
End If
End With
End With
End Sub
'シート( "CUSTOMERLIST")範囲場合。( "A2:A5")=レンジ( "C10")は値Then'は'バリアントを比較しています() '(左側)には「Variant」が右側に表示されます。配列の平等をテストすることはできません。 – Comintern
これを修正するにはどうすればいいですか? –
比較対象の内容によって異なります。 – Comintern