アプリ版:「スタンプのみでお礼する」機能のリリースについて

以下のようなものを作成しましたが、1シートでは、問題なく回るものの2シート目のmをFINDしているところでエラーが発生します。原因は、該当するmが存在しないためだと思うのですが、そのような場合にエラーを回避し、次のシートへ飛びエラーが発生したシート番号を最後に表示してほしいです。

そのようなことは可能でしょうか?
読みにくいプログラムかもしれませんが、よろしくお願いします。

Dim top, m, under, bottom, cnt, she

Application.ScreenUpdating = False '画面固定
cnt = Sheets.Count 'シートの数

For she = 1 To cnt
Sheets(she).Activate

Columns("F:F").Select
Selection.Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, MatchByte:=False, SearchFormat:=False).Activate

top = ActiveCell.Row - 1

Rows("1:" & Format(top)).Select
Selection.Delete Shift:=xlUp
Range("A1").Select

m = Range("E1") + 10
If m >= 60 Then
m = m - 60
Else
m = m
End If

Columns("E:E").Select
Selection.Find(What:=Format(m), After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, MatchByte:=False, SearchFormat:=False).Activate

under = ActiveCell.Row
bottom = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row - 1

Rows(Format(under) & ":" & Format(bottom)).Select
Selection.Delete Shift:=xlUp
Range("A1").Select

Next she

End Sub

A 回答 (1件)

以下のコードは参考になりませんか?


Sub Macro1()
Dim rg As Range
Set rg = Columns("F:F").Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, MatchByte:=False, SearchFormat:=False)
If rg Is Nothing Then
MsgBox "ありませんでした"
Else
MsgBox rg.Row
End If
End Sub

この回答への補足

お礼の文章の後に、補足というのも変ですが。

Set rg = Columns("E:E").Find(m)

If rg Is Nothing Then
MsgBox "以下のシートには、該当行がありません。" & vbNewLine & ActiveSheet.Name
Else

under = rg.Row
bottom = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row - 1

Rows(Format(under) & ":" & Format(bottom)).Select
Selection.Delete Shift:=xlUp
Range("A1").Select

End If

素直にFIND(検索したい数字)で通りました。

補足日時:2008/12/18 01:10
    • good
    • 0
この回答へのお礼

回答ありがとうございます。

自分のと同様に
Set rg = Columns("F:F").Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, MatchByte:=False, SearchFormat:=False)
の部分が実行時エラー13と表示されうまくいきません。
Is Nothing というのは自分も見つけることができましたが、うまく回避できません。おわかりでしたら、よろしくお願いします。

お礼日時:2008/12/18 00:57

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!