Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > If statement or function?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2004, 05:57 PM
Joe100 Joe100 is offline
Regular
 
Join Date: Mar 2004
Location: USA
Posts: 95
Default If statement or function?


I have a spreadsheet with 10 columns. In the 11th column I want the word error to appear if the data in any of the 10 columns is not a number, or is a number less than or equal to 0.

Would the best way to do this be to write a function for column 11, or use an if statement?
Reply With Quote
  #2  
Old 05-16-2004, 06:40 PM
Michael_I Michael_I is offline
Contributor

* Expert *
 
Join Date: Dec 2001
Posts: 725
Default

Does it need to be done through code? You could enter a couple of if statements in a formula in column 11. If through code, then I would use a For/Next function for each column 1-10.
Reply With Quote
  #3  
Old 05-16-2004, 09:07 PM
Kluz's Avatar
Kluz Kluz is online now
Sapience.Aquire

Super Moderator
* Expert *
 
Join Date: Oct 2003
Location: Lake Bluff, Ill., U.S.
Posts: 3,306
Default

To do this with a cell equation you will need to use an array formula. Assuming the first 10 columns contain your data and they start at row 1 enter this equation into the formula bar while cell K1 is selected:
Code:
=IF(ISNUMBER(A1:J1),"","error")
Instead of hitting just 'Enter' hit Ctrl + Shift + Enter you should see in the formula bar squiggle brackets: {} around the above cell equation.
__________________
No the other right mouse click
Reply With Quote
  #4  
Old 05-17-2004, 05:59 PM
Joe100 Joe100 is offline
Regular
 
Join Date: Mar 2004
Location: USA
Posts: 95
Default

Thank you both for your replies. I tried the iserror array formula and it didn't seem to work for me. Perhaps I was using it wrong. I am going to pose a different question to see if I can find out what I am looking for. Again thanks.
Reply With Quote
  #5  
Old 05-17-2004, 06:16 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Hmmm... the formula looks all right, but doesn't work for me either.

Here's a workaround... a bit of a kludge, but works. Again, Ctrl+Shift+Enter to enter it.
=IF(SUM(NOT(ISNUMBER(A1:J1))*1)>0,"error","ok")
Reply With Quote
  #6  
Old 05-17-2004, 08:13 PM
Kluz's Avatar
Kluz Kluz is online now
Sapience.Aquire

Super Moderator
* Expert *
 
Join Date: Oct 2003
Location: Lake Bluff, Ill., U.S.
Posts: 3,306
Default

Quote:
Originally Posted by Joe100
I tried the iserror array formula and it didn't seem to work for me.
Umm... what iserror formula?
That's weird, it works once or twice then stops working. Herilane's works fine though and still works even if it's not an array formula. Still trying to wrap my head around why you would need to multiply 1 Last time I checked multiplying anything by 1 results in the same value. Thank you Microsoft!
__________________
No the other right mouse click
Reply With Quote
  #7  
Old 05-17-2004, 08:44 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

I'm not that great at this Array Formula stuff, but I'm sure Helen can clarify this tomorrow... but I do know why multiplying by 1 is necessary. It is because the =Sum() function cannot Sum boolean values such as 'True'. But you can coerce the value, using True * 1 = 1 and False * 1 = 0. (In VBA True * 1 = -1, so one has to be careful! ) This "multiply by 1" technique is, more or less, the Excel Worksheet's method of effecting CLng(), if you will...
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #8  
Old 05-18-2004, 03:22 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

An other formula way (not an array one) to achieve it...
Code:
=IF(OR(COUNTIF(A1:J1,"*")>0,COUNTIF(A1:J1,"<=0")>0),"ERROR","WHATEVER…")

Last edited by italkid; 05-18-2004 at 03:38 AM. Reason: Misread the initial question...ooops
Reply With Quote
  #9  
Old 05-18-2004, 05:42 AM
Joe100 Joe100 is offline
Regular
 
Join Date: Mar 2004
Location: USA
Posts: 95
Default

Thank you all. I haven't tried them yet but I feel sure that Herilane's and Talkids solutions will work. Thanks to Mike for telling us why you need to multiply by 1 in Herilane's formula. I was curious about that myself.
Reply With Quote
  #10  
Old 05-18-2004, 04:15 PM
Kluz's Avatar
Kluz Kluz is online now
Sapience.Aquire

Super Moderator
* Expert *
 
Join Date: Oct 2003
Location: Lake Bluff, Ill., U.S.
Posts: 3,306
Default

Thanks for that clarification Mike.
__________________
No the other right mouse click
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Safe Custom Tooltips Xstatic Interface and Graphics 10 03-08-2005 11:46 PM
Addressof Operator vbNEMESIS Word, PowerPoint, Outlook, and Other Office Products 1 07-02-2003 01:05 PM
Iframe Color vbSIME Web Programming 10 02-10-2003 01:13 PM
Help! HTML Parsing doublea Web Programming 0 02-04-2003 11:16 PM
It's whats inside that counts! Dazz API 4 04-27-2001 05:16 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->