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???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Count merged cells 1
Error in Macro 2003 2
Open workbook 2
Excel Excel VBA (Saving as A CSV) 1
Select Case 5
Run time error message???....Help!! 12
Please help with selecting a range 7
Case Statement 3

Back
Top