以下のようなものを作成しましたが、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
No.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(検索したい数字)で通りました。
回答ありがとうございます。
自分のと同様に
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 というのは自分も見つけることができましたが、うまく回避できません。おわかりでしたら、よろしくお願いします。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・14歳の自分に衝撃の事実を告げてください
- ・架空の映画のネタバレレビュー
- ・「お昼の放送」の思い出
- ・昨日見た夢を教えて下さい
- ・【お題】絵本のタイトル
- ・【大喜利】世界最古のコンビニについて知ってる事を教えてください【投稿~10/10(木)】
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
DVDDecrypterで以下のエラーが...
-
重大なエラーが検出されました
-
交通系icカードとクレカの磁気...
-
GOM-playerでスクリプトエラー...
-
REAPERでvstを大量に読み込むと...
-
みつも郎liteのファイルがエラ...
-
「空吸引」を英語でなんと訳す...
-
エラー:93 クラス文字列が無...
-
Chrome 設定 ブルースクリーン
-
エラー発生!?エラーの元がわか...
-
グーグルのGメイルが突然受信で...
-
IE8「規定検索プロバイダー設定...
-
MSNメッセンジャーが突然強制終...
-
ツイッターでページでエラーが...
-
「このURLはコンテンツブロッカ...
-
右クリックで画像コピー やば...
-
動画のダウンロードが突然出来...
-
勝手にダウンロードされた Web...
-
アンインストールしたプログラ...
-
アダルトサイトの入会表示をシ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
交通系icカードとクレカの磁気...
-
「このURLはコンテンツブロッカ...
-
富士通SystemwalkerOperationMa...
-
インターナルエラー:GEDIT 3 ...
-
以前作ったエクセルファイルを...
-
REAPERでvstを大量に読み込むと...
-
ソフトウエアー エラー???
-
GOM-playerでスクリプトエラー...
-
みつも郎liteのファイルがエラ...
-
ラスタライズのエラー
-
icucnv58.dll が見つからないた...
-
aviutlによるxvidエンコードで…
-
このサイトで無限リダイレクト...
-
エラーが頻発して困ってます ...
-
どのようなランタイムを入れれ...
-
jimdoのHPが見られない
-
CANONのMG6930っていう機種でエ...
-
BKTask.exeの停止事象について
-
勘定奉行でのSQLエラー
-
Illustrator8.0のエラー
おすすめ情報