2

エラー424オブジェクトが必要なコードを取得しています

lr = Range("O:O").Cells(Rows.Count, 1).End(xlUp).Row

For y = 0 To UBound(myVariable)
    a = myVariable(y)
    Range("O:O").Select
    Set objXL = GetObject(, "Excel.Application")
    Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    If z = "True" Then
        ActiveCell.Delete shift:=xlUp
    End If
    MsgBox z.Value
Next
4

1 に答える 1

1

Find は範囲Objectを取得します。したがって、次のいずれかを行います。

a) 見つかった範囲を有効にする

Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

また

b)見つかった範囲を変数に割り当てます

Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)      'No .Activate in here '

両方を同時に使用すると、エラーが発生します。

ノート:

注意してください。.Find一致が見つからない場合は、 を取得しますNothing。このような場合、.Activateはエラー メッセージを表示します。したがって、ここでいくつかのエラー処理を使用してください。

于 2012-11-23T09:13:34.280 に答える