9/07/2012

利用VBA檢查是否為合併儲存格

  1. 進入Excel後,開啟Microsoft Visual Basic Editor ( 按 Alt + F11 )


  2. Insert (輸入) > Model (模組)


  3. 輸入程式如下,完畢後關閉Microsoft Visual Basic Editor 

  4. Option Explicit
    Public Function CheckMerged(Cx As Integer, Cy As Integer) As Boolean
        CheckMerged = Cells(Cx, Cy).MergeCells
        If CheckMerged Then
            MsgBox "It is Merged"
        Else
            MsgBox "It isn't Merged"
        End If
    End Function


  5. 在工作表輸入並指定儲存格,是合併儲存格畫面


  6. 在工作表輸入並指定儲存格,不是合併儲存格畫面