Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Ranges vs cells with VBA


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Ranges vs cells with VBA

Okay, if I disable the events and clear the area and then enable the events
the problem goes away. How can I handle the situation if the user manually
tries to clear all the cells at once (because then I still get hung up in the
original if statement.

Sub ClearSingle()
Application.EnableEvents = False
shtSingleDeposits.Range("B4:C8").ClearContents
shtInput.Range("InpSingleInd") = "No"
Application.EnableEvents = True
End Sub
--
Wag more, bark less


"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Ranges vs cells with VBA

IsEmpty does not exist to check if a cell is empty or not... it is used to
determine if a variable is initialize or not. You could test whether the
length of the contents of the cell are zero or not. Try this...

If Target.Column = 2 And Not IsDate(Target.Value) And Len(Target.Value) 0
Then

Your newsreader will probably word wrap the above single line of code.

--
Rick (MVP - Excel)


"Brad" wrote in message
...

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Ranges vs cells with VBA

Of course, if I had bothered to check before I posted my response, I would
have seen that VBA appears to have extended the functionality of IsEmpty to
cells in a spreadsheet... IsEmpty does, in fact, work for checking if a cell
is empty or not. However, if the cell contains a formula, even if the result
of that formula is the empty string (""), IsEmpty will report False. The Len
function check I posted will report 0 (empty string) for this situation.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
IsEmpty does not exist to check if a cell is empty or not... it is used to
determine if a variable is initialize or not. You could test whether the
length of the contents of the cell are zero or not. Try this...

If Target.Column = 2 And Not IsDate(Target.Value) And Len(Target.Value)
0 Then

Your newsreader will probably word wrap the above single line of code.

--
Rick (MVP - Excel)


"Brad" wrote in message
...

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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Ranges vs cells with VBA

Of course, this all depends on whether you are looking for empty cells or
zero value cells. If you want absolutely empty, then IsEmpty will do that.

"Rick Rothstein" wrote:

Of course, if I had bothered to check before I posted my response, I would
have seen that VBA appears to have extended the functionality of IsEmpty to
cells in a spreadsheet... IsEmpty does, in fact, work for checking if a cell
is empty or not. However, if the cell contains a formula, even if the result
of that formula is the empty string (""), IsEmpty will report False. The Len
function check I posted will report 0 (empty string) for this situation.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
IsEmpty does not exist to check if a cell is empty or not... it is used to
determine if a variable is initialize or not. You could test whether the
length of the contents of the cell are zero or not. Try this...

If Target.Column = 2 And Not IsDate(Target.Value) And Len(Target.Value)
0 Then

Your newsreader will probably word wrap the above single line of code.

--
Rick (MVP - Excel)


"Brad" wrote in message
...

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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Ranges vs cells with VBA

IsEmpty requires a Variant, so what is happening is that under the covers
the Range is being coerced to a variant and then IsEmpty will check the
first cell in the resulting variant array contained in the implied variant.

If the range is multi cell then you need a different strategy (looping,
Countif ..) to check for IsEmpty.
Also note that a not-yet calculated cell returns Empty ...

regards
Charles

"Rick Rothstein" wrote in message
...
Of course, if I had bothered to check before I posted my response, I would
have seen that VBA appears to have extended the functionality of IsEmpty
to cells in a spreadsheet... IsEmpty does, in fact, work for checking if a
cell is empty or not. However, if the cell contains a formula, even if the
result of that formula is the empty string (""), IsEmpty will report
False. The Len function check I posted will report 0 (empty string) for
this situation.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
IsEmpty does not exist to check if a cell is empty or not... it is used
to determine if a variable is initialize or not. You could test whether
the length of the contents of the cell are zero or not. Try this...

If Target.Column = 2 And Not IsDate(Target.Value) And Len(Target.Value)
0 Then

Your newsreader will probably word wrap the above single line of code.

--
Rick (MVP - Excel)


"Brad" wrote in message
...

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






  #8   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coping ranges of cells David Excel Programming 4 July 2nd 07 07:12 AM
ADD DIFFERENT RANGES OF CELLS Add non continuous ranges of cells Excel Discussion (Misc queries) 4 June 27th 06 01:15 AM
specifying ranges using cells Mitch Excel Programming 1 June 17th 05 10:13 PM
empty cells in ranges UniDave Excel Discussion (Misc queries) 2 November 26th 04 02:18 AM
Special Ranges of Cells BOHICA Excel Programming 2 December 12th 03 12:05 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"