Select case bugging out

  • Thread starter Thread starter jlclyde
  • Start date Start date
J

jlclyde

Any idea on why I keep getting Application-defined or object-defined
error when it gets to this line of code?

Select Case Selection.MergeArea.Cells.Count

Thanks in advance for the help.
Jay
 
That's a gotcha!

In the help, there's a  remark:
"The MergeArea property only works on a single-cell range."
but if you select a merged area, -Selection -HAS to be a multiple cell
range!
To solve use:
Select Case
Selection.Cells(1).MergeArea.Cells.Count

You are now my hero! I have been banging my head against the wall for
hours on this one.
Thanks,
Jay
 
Depends on what your selection is. The merge area property only works if the
range (in this case Selection) is a single cell. For example try this...
Create a Merger area of cells A1:B2
Now run this code...

MsgBox Range("A1").MergeArea.Cells.Count

and you will get 4.

This code will not work

MsgBox Range("A1:B1").MergeArea.Cells.Count

as the merge area for A1 and B1 may or may not be the same (it is in this
case but it does not have to be)...

Now to the big question... What exactly are you trying to do???
 
Back
Top