Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@ayaki067

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

More than 1 year has passed since last update.

備忘録
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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ayaki067
Javaエンジニア:2年目

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?