[[20221124115204]] 『Excelで条件にあったセルを空白にする処理をしたax(おもち) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『Excelで条件にあったセルを空白にする処理をしたいです』(おもち)

   A B C D E F G H I J K L M ・・・
1       *  *       * * *
2    * *       * * * * *
3    * * * * * *
4  *   * * * * *   * *
5

今 * のところに数値が入っていてその他のセルは空白の状態です。
M列以降、5行目以降にもデータがあります。
ここで、横に5つ以上連続で数値が入っているセルだけ残し、4連続以下のセルを空白にしたいです。
C1,E1,I1,J1,K1,B2,C2,A4,I4,J4のセルを空白にする方法を教えていただけないでしょうか。

VBA初心者で、何度考えてもわからないのでお教え頂けると嬉しいです

< 使用 Excel:Excel2016、使用 OS:Windows10 >


Sub test()
Dim rmax As Long, cmax As Long
Dim r As Long, c As Long
Dim sc As Long
Dim cnt As Integer
With ActiveSheet
rmax = .UsedRange.Rows.Count
cmax = .UsedRange.Columns.Count
For r = 1 To rmax
For c = 1 To cmax
If .Cells(r, c).Value <>""Then
sc = c
cnt = 0
Do Until Cells(r, c).Value = ""Or c >cmax
cnt = cnt + 1
c = c + 1
Loop
If cnt <= 4 Then
.Range(.Cells(r, sc), .Cells(r, c - 1)).ClearContents
End If
End If
Next c
Next r
End With
End Sub

だとうまくいかないんです、
(おもち) 2022/11/24(木) 15:37:37


 Sub sample()
  Dim aRow As Range, Rng As Range, aArea As Range
  For Each aRow In ActiveSheet.UsedRange.Rows
      Set Rng = Nothing
      On Error Resume Next
         Set Rng = aRow.SpecialCells(xlCellTypeConstants, xlNumbers)
      On Error GoTo 0
      If Not Rng Is Nothing Then
         For Each aArea In Rng.Areas
            aArea.Select
            MsgBox "セルの数: " & aArea.Cells.Count
         Next
      End If
  Next
 End Sub
(´・ω・`) 2022/11/24(木) 16:21:54

コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.