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?

More than 5 years have passed since last update.

Javaコメントカウント(VBA資材)

Posted at

備忘録
2020/02.24
単体コメントカウント

Option Explicit
Const Start_Row As Integer = 3
Const Start_Col As Integer = 2
Const Start_msg As String = "ここにスタートコメント"
Const End_msg As String = "ここにエンドコメント"

Sub Delコメントカウント()
Dim i As Integer
Dim MaxRow As Long
Dim DelCount As Long
Dim checkStr As String
Dim checkPoint As Boolean
checkPoint = False

' B列の最後行を取得
MaxRow = Range("B65536").End(xlUp).Row
For i = 3 To MaxRow
    checkStr = Cells(i, Start_Col).Value
    checkStr = Trim(checkStr)

'    スタートメッセージもしくは2周目の場合
    If checkStr = Start_msg Or checkPoint Then
        checkPoint = True
        checkStr = Left(checkStr, 1)
    
        ' /コメント判定
        If checkStr = "/" Then
        ' *コメント反映
        ElseIf checkStr = "*" Then
        ' 空白行判定
        ElseIf checkStr = "" Then
        Else
        ' 2周目フラグに真を設定
        ' カウント数インクリメントする
            DelCount = DelCount + 1
        End If
    End If

    ' エンドメッセージの場合
    If checkStr = End_msg Then
        ' 2周目フラグに偽を設定
        checkPoint = False
        ' スタート、エンドメッセージ分カウントを引く
        DelCount = DelCount - 2
    
    End If

Next i

MsgBox DelCount
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?