pgbigorokuのブログ

プログラムの再利用できそうなコードをアップ

EXCEL VBA 選択したセルすべてが結合セルの1つの場合

            If nirngSelectionの1つ目のセル.MergeArea.Address = Selection.Address Then
                      '選択したセルすべてが結合セルの1つの場合
           End If

' Selectionの1つ目のセル
' https://blog.hatena.ne.jp/nakairo/pgbigoroku.hatenablog.com/edit
' 2021/8/21
Public Function nirngSelectionの1つ目のセル() As Range
    Dim strSelection As String
    strSelection = Selection.Address
    strSelection = nistr文字列検索をして1つ目の区切り位置までの値を取得(strSelection, ",")
    strSelection = nistr文字列検索をして1つ目の区切り位置までの値を取得(strSelection, ":")
    Set nirngSelectionの1つ目のセル = Range(strSelection)
End Function

' 文字列検索をして1つ目の区切り位置までの値を取得
'https://pgbigoroku.hatenablog.com/entry/2022/08/23/161312
' 2021/8/21
Public Function nistr文字列検索をして1つ目の区切り位置までの値を取得(ByVal pstrTarget As String, ByVal pstrDivide As String)
    Dim intInstr As Integer
    intInstr = InStr(pstrTarget, pstrDivide)
    If intInstr = 0 Then
        nistr文字列検索をして1つ目の区切り位置までの値を取得 = pstrTarget
    Else
        nistr文字列検索をして1つ目の区切り位置までの値を取得 = Left(pstrTarget, intInstr - 1)
    
    End If
End Function