[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『複数条件』(ドラ)
一定の範囲のセルが「0」もしくは空白の時にその列を削除します
一定の範囲とは偶数列とその右隣の列の最終行〜2行上までです
例えばB・C列、D・E列、F・G列となります
下の表の場合はB・C列は何もしない、
D・E列も何もしない、F・G列は削除、H・I列も削除となります
B C D E F G H I
2行上 5 0 0
1行上 35 0
最終行 11 2 0
自動でできるようにしたいんですがどうやっていいか分かりません
教えてくれないですか
Sub テスト()
Dim i As Long
Dim j As Long
g = Cells(Rows.Count, 1).End(xlUp).Row r = Cells(1, Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False
For i=
For j = 2 To r Step 2
If Cells(g, i) <> "" Then
Next i
Application.ScreenUpdating = True
End Sub
< 使用 Excel:Office365、使用 OS:Windows10 >
>F・G列は削除、H・I列も削除となります
削除とは、クリアと同じ意味ですよね?
Sub テスト() Dim stRw As Long, rightestCL As Long Dim r As Range Dim j As Long
stRw = Cells(Rows.Count, 1).End(xlUp).Row - 2 rightestCL = Cells(1, Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False
For j = 2 To rightestCL Step 2 Set r = Cells(stRw, j).Resize(3, 2) If Application.CountIf(r, 0) + Application.CountIf(r, "") = 6 Then r.Clear End If Next j
Application.ScreenUpdating = True End Sub
(半平太) 2020/05/19(火) 15:00
r.Clear
↓
Columns(j, j + 1).Delete
実行時エラー1004
「アプリケーション定義またはオブジェクト定義のエラーです」
(ドラ) 2020/05/19(火) 16:39
列削除だったんですか。なら、
Sub テスト() Dim stRw As Long, rightestCL As Long Dim r As Range Dim j As Long
stRw = Cells(Rows.Count, 1).End(xlUp).Row - 2 rightestCL = Cells(1, Columns.Count).End(xlToLeft).Column - 1 rightestCL = Application.Even(rightestCL)
Application.ScreenUpdating = False
For j = rightestCL To 2 Step -2 Set r = Cells(stRw, j).Resize(3, 2) If Application.CountIf(r, 0) + Application.CountIf(r, "") = 6 Then r.EntireColumn.Delete End If Next j
Application.ScreenUpdating = True End Sub
(半平太) 2020/05/19(火) 16:55
列全体を取得しないといけなかったんですね
ありがとうございます
(ドラ) 2020/05/20(水) 09:19
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.