2016-10-17 11 views
0

最初の36行で動作するマクロがありますが、実行時エラーが表示されます。 findステートメントのエラーを表示します。マクロの目的は、列に配置された図の90パーセンタイルを計算し、パーセンタイル以上の値の数を数え、さまざまな部門に分割を提供することです。誰でもエラーを修正するために私を助けてもらえますか?VBAランタイムエラー91 - 2

For bb = 1 To temcnt 
cc = Sheets("tem").Cells(bb, ttc + 4).Value 
Sheets("Geographic Strength").Activate 
Cells.Find(What:=cc, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
    False, SearchFormat:=False).Activate 

    ff1 = ActiveCell.Column 
    Sheets("tem").Activate 
    rnggg = Range(Cells(2, 6), Cells(ttr, 6)) 
    mamm = WorksheetFunction.CountIf(Range(Cells(2, 6), Cells(ttr, 6)), cc) 
Sheets("geographic strength").Activate 
f222 = Sheets("individual strength").Cells(1, iii).Value 

**Cells.Find(What:=f222, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
    False, SearchFormat:=False).Activate 
    f333 = ActiveCell.Row** 

'Error is in the above statement(Cells.Find) 

Cells(f333, ff1).Value = mamm 
Next bb 
Sheets("tem").Delete 
Next iii 
Application.DisplayAlerts = True 
Application.ScreenUpdating = True 
End Sub 
+0

'.Activate'を使うと、' .Select'などは一般に悪い考えです.bマクロを遅くし、間違いのリスクを高めます。 [Here](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros)と[here](http://stackoverflow.com/documentation/excel) -vba/1107/vba-best-practices/9292/avoid-using-select-or-activate)は、回避方法のヒントです。 – arcadeprecinct

答えて

1

それはだ

Cells.Find(What:=f222, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
    False, SearchFormat:=False) 

はそれがNothingを返しますので、希望のセルを見つけることに成功しなかった、と次のようにあなたがActivateNothing

はそうあなたが行くことができない理由は次のとおりです。

'... your code before 
f222 = Sheets("individual strength").Cells(1, iii).Value 

Dim found As Range 
Set found = Cells.Find(What:=f222, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
False, SearchFormat:=False) 

If Not found Is Nothing Then '<-- check if any cell has been found 
    found.Activate 
    f333 = ActiveCell.Row 

    '... rest of your code should f222 have been found 

End If 

' rest of your code 
+0

ありがとうございました。今は完璧に動作しています。 :) –

関連する問題