View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Ranges vs cells with VBA

You could throw up your hands and quit if the number of cells is greater than 1.

If target.cells.count 1 then exit sub

or you could loop through each cell in the range to inspect.

dim rngToInspect as range
dim myIntersect as range
dim myCell as range

set rngtoinspect = me.range("b:b")

set myintersect = intersect(target,rngtoinspect)

if myintersect is nothing then
exit sub
end if

for each mycell in myintersect.cells
if isempty(mycell.value) then
'it's empty
else
if isdate(target.value) then
'it's a date
else
'not a date
end if
end if
next mycell


Brad wrote:

If I delete each cell in a range manually - I do not get hung up in the
below "if statement". If try to "clearcontents" to the entire range - it
doesn't recognize the isEmpty(Target.value) (I believe). What options do I
have...

If Target.Column = 2 And Not IsDate(Target.Value) And Not
IsEmpty(Target.Value) Then
MsgBox ("Inputs have to be dates")
Target.ClearContents
End If


--

Dave Peterson