Checking if ranges are the same after Range.EntireColumn

  • Thread starter Thread starter jc
  • Start date Start date
J

jc

running the following code

If Selection = Selection Then MsgBox "ok"
If Selection.EntireColumn = Selection.EntireColumn Then MsgBox "ok"--
If Selection.EntireColumn.Cells(10) = Selection.EntireColumn.Cells(10) Then
MsgBox "ok"

the first line works
the second line results in a run-time error '13': Type mismatch
the third line works

can anyone explain why 2nd line doesn't work ?

JC
 
In your 1st & 3rd lines Selection & .Cells(10) returns the value of a
single cell. Both sides of the = being the same the msgbox shows "ok"

In your 2nd line, Selection returns a 2d array of all cell values in the
column.
If you try and do
myArray = myArray
you will get the same error

Of course if had you selected two or more cells your 1st line would have
failed for the same reason.

Regards,
Peter T
 
If you're just looking to see if the selection is an entire column:

if selection.address = selection.entirecolumn.address then
 

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

Back
Top