Link to home
Start Free TrialLog in
Avatar of everycloud
everycloudFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can I use VB.Net to identify merged cells within an xlsx file?

Hello,

I'm trying to make sure a spreadsheet that I want to import into a database does not contain any merged cells within a specified area. Is there a way to identify merged cells using VB.Net?
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is a VBA function but should be easily transferable to VB.Net. It uses the FindFormat method to locate any merged cells in the specified worksheet and returns True or False depending on whether any are found.

Function ContainsMergedCells(ws As Worksheet) As Boolean
    Dim MergedCells As Range
    Application.FindFormat.MergeCells = True
    Set MergedCells = ws.Cells.Find(What:="", SearchFormat:=True)
    If MergedCells Is Nothing Then
        ContainsMergedCells = False
    Else
        ContainsMergedCells = True
    End If
End Function

Open in new window