![]() |
Code doesn't go past first IF statement
Matt wrote :
... I can't seem to get it to check the value of the cell after the user inputs a code and have it compare the data in an if/elseif statement. Any ideas would be great. Thanks. Matt If Target.Cells.Count 1 Then Exit Sub If NOT Intersect(Target, Me.Range("C13:C15")) Is Nothing Then -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam |
Code doesn't go past first IF statement
Matt wrote :
When I add NOT in the code, it doesn't do anything at all. Matt Ouch :( Lets try again.. in this line Range("D10") Is Not Null you are comparing a range OBJECT to Null... which wont work.. you want to check that the range is not an empty cell. following is almost equivalent: If NOT IsEmpty(Range("d10")) then if Range("D10") < "" then if Len(Range("d10") < 0 then if Len(Trim(Range("d10")) < 0 then 'last one would also check for cells where the user cleared the cell with his spacebar.. Re syntax: in VBA syntax uses IS only to compare OBJECTS. and that the Null value is not used very often in Excel. Intersect(Target,Range("d10")) returns a range object Compare it to the NOTHING object Negate would lead to : If NOT intersect(a,b) IS nothing whereas If Intersect(a,b) IS NOT NOTHING gives a syntax error. -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam |
Code doesn't go past first IF statement
That worked. Thanks. Any ideas on how to check 6 other ranges on the same sheet? With an if/elseif statement. It seems like if I put too much code in the worksheet_change sub some of the other code in the sub doesn't run too well. Any ideas? Thanks again. Matt
"keepITcool" wrote: Matt wrote : When I add NOT in the code, it doesn't do anything at all. Matt Ouch :( Lets try again.. in this line Range("D10") Is Not Null you are comparing a range OBJECT to Null... which wont work.. you want to check that the range is not an empty cell. following is almost equivalent: If NOT IsEmpty(Range("d10")) then if Range("D10") < "" then if Len(Range("d10") < 0 then if Len(Trim(Range("d10")) < 0 then 'last one would also check for cells where the user cleared the cell with his spacebar.. Re syntax: in VBA syntax uses IS only to compare OBJECTS. and that the Null value is not used very often in Excel. Intersect(Target,Range("d10")) returns a range object Compare it to the NOTHING object Negate would lead to : If NOT intersect(a,b) IS nothing whereas If Intersect(a,b) IS NOT NOTHING gives a syntax error. -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam |
All times are GMT +1. The time now is 02:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com