Message Box to Appear if Cell Values In Range Differ

M

Monk

Hi

I am currently pasting worksheet data into a new spreadsheet and all the
dates in the cell range C2:C500 should be the same. However from time to time
one or two dates may differ. I would like a message box to appear as soon as
the data is pasted in to the new sheet if any on the dates in the range
should not be identical.

Any assistance you could provide would be appreciated.

Thanks

Monk
 
B

Bob Phillips

IF Application.COUNTIF(Range("C2:C500"), Range("C2).Value) <>
Range("C2:C500").Cells.Count Then

Msgbox "not all the same"

End If
 
M

Monk

Thanks Bob. This works well but I forgot to advise that within that range
there may be blank cells. Can you please advise how this would be modified
to ignore blank cells within that C2:C500 range so that the error message
will only appear if data appears within that range?

Cheers

Monk
 
B

Bob Phillips

Just change it to this

If Application.CountIf(Range("C2:C500"), Range("C2").Value) <> _
Application.CountA(Range("C2:C500")) Then

MsgBox "not all the same"
End If
 
M

Monk

Thanks Bob. Works perfectly. Much appreciated

Bob Phillips said:
Just change it to this

If Application.CountIf(Range("C2:C500"), Range("C2").Value) <> _
Application.CountA(Range("C2:C500")) Then

MsgBox "not all the same"
End If


--
__________________________________
HTH

Bob
 

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

Top