入力された要求番号を検索し、検索中のセルから情報をセルに配置する検索機能を作成しようとしています。元の式からシート名と範囲のみを変更しました。他に違いはありません。エラーが出る
'1004' "Unable to get the Activate property of the Range class"
.activateで
前にアクティベートを挿入することでコードを機能させることができました
dim ReqNumber
それはうまくいきましたが、今では検索メソッドに必要なオブジェクトが最初から教えられています。
set cF= .Find
それは私に問題を与えています。今何が間違っているのかよくわかりません。
Dim ReqNumber As Variant
ReqNumber = InputBox("Please Enter Requisition Number", "Information")
Dim FirstAddress As String, cF As Range
With ThisWorkbook.Sheets(" MthruF Schedule").Range("A:A")
.Cells(1, 1).Activate
'First, define properly the Find method
Set cF = .Find(What:=ReqNumber, _
after:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
'If there is a result, keep looking with FindNext method
If Not cF Is Nothing Then
FirstAddress = cF.Address
Do
cF.Offset(0, 8).Value = ReqNumber
cF.Offset(0, 9).Value = EmpInfo.FirstName.Value & " " & EmpInfo.LastName.Value
cF.Offset(0, 10).Value = EmpInfo.ComboBox3.Value & "/" & EmpInfo.ComboBox20.Value & "/" & EmpInfo.YearCmb.Value
cF.Offset(0, 11).Value = EmpInfo.AgencyBox.Value
Set cF = .FindNext(cF)
'Look until you find again the first result
Loop While Not cF Is Nothing And cF.Address <> FirstAddress
End If
End With
関連した質問
私考える コードを実行するときに間違ったシートが選択されているためです。
正しいシートにいない場合、このコードは失敗します。
どのシートに関係なく検索を実行するには、
.Cells(1,1).Activate
を削除します line-セルを選択したりアクティブにする必要はありません。で
FIND
ActiveCell
を置き換える.Cells(1,1)
と 。これらの変更により、
FIND
MthruF Schedule
の列Aを常に見る セルA1
から開始 どのシートを使用していても。編集:
値を変更していないので、
Not cF Is Nothing
を持っている必要はありません。 あなたのループで。ザ・FIND
値を変更しない限り常に値を見つけます-そのため、cF.Address <> FirstAddress
。