0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

1分で分かるVBAコード解説

Last updated at Posted at 2025-04-19

エクセルのシートG列に12以上の数字のセルがあった場合、そのセルの値を削除するコード

Sub JyuryouSakujo() #「JyuryouSakujo」というサブプロシージャ名

Dim lastRow As Long #「lastRow」というロング型の変数
Dim r As Long #「r」というロング型の変数
Dim rowCount As Long #「rowCount」というロング型の変数
Dim Cstrnum As Integer #「Cstrnum」という整数型の変数
 
 lastRow = Range("G" & Rows.Count).End(xlUp).Row #「lastRow」にG列の最終行数を代入
 
For r = 1 To lastRow #1から開始して「lastRow」の数字まで繰り返す。
     Cstrnum = Range("G" & (r)) #「Cstrnum」にG列の「r」の行数のセルの値を代入
   If Cstrnum > 11 Then #「Cstrnum」が12以上の場合「End If」までの処理を実行
     Range("G" & (r)).EntireRow.Delete #G列の「r」の数字のセルの値を削除
     r = r - 1 #「r」に代入されている数字から1引き算する
   Else
   End If
Next

End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?