Excel VBA Function to find and give me the row number of the first merged cell in a column

maverick93

New Member
Joined
Jan 7, 2010
Messages
23
I am in need of a function to find and give me the row number of the first merged cell in a column.

Right now I have a list A1:C100 and none of those cells are merged accept one row Merge cell. I need a function that will locate this merged cell and return a row number.


so if the the merged cell is in A20:C20 I need the function to return the row number which would be 20.

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Something like this?
Return of 0 means no merged rows

VBA Code:
Sub Test()
  Dim FirstMergeRow As Long
  
  FirstMergeRow = Merge_Row(Range("A1:A100"))
  MsgBox FirstMergeRow
End Sub

Function Merge_Row(rng As Range) As Long
   Application.FindFormat.Clear
   Application.FindFormat.MergeCells = True
   On Error Resume Next
   Merge_Row = rng.Find(What:="", After:=rng.Cells(rng.Cells.Count), SearchDirection:=xlPrevious, SearchFormat:=True).Row
   On Error GoTo 0
   Application.FindFormat.Clear
End Function
 
Upvote 0
Hello Peter_SSs,

Thank you so much for your help. Unfortunately the code doesn't quite work the way that I need. It is actually giving me the row number of the last merged cell and not the first.

I figured this would be a tough one so thanks for the try!
 
Upvote 0
It is actually giving me the row number of the last merged cell and not the first.

I figured this would be a tough one so thanks for the try!
No, it isn't tough (I don't think) - I just made an error. Try this change to the line in question.

Rich (BB code):
Merge_Row = rng.Find(What:="", After:=rng.Cells(rng.Cells.Count), SearchDirection:=xlNext, SearchFormat:=True).Row
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top