Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Macro for Looping for Criteria Checking

Can some1 pls give me an idea of how to design a simple "4" step looping
structure macro e.g.

If(A1=1,"a",if(a1<1,"b",if(a11,"c",if(not(isblank (a1)),"d","e"))))
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Macro for Looping for Criteria Checking

If you wish to use that as a worksheet formula, try it this way:
=IF(ISBLANK(A1),"e",IF(A1=1,"a",IF(A1<1,"b",IF(A1 1,"c","d"))))

You need to test the ISBLANK early because if you do not then Excel
interprets it as 0 and the A1<1 test ends up being true before you finish
testing within the nested IF statements.

"FARAZ QURESHI" wrote:

Can some1 pls give me an idea of how to design a simple "4" step looping
structure macro e.g.

If(A1=1,"a",if(a1<1,"b",if(a11,"c",if(not(isblank (a1)),"d","e"))))

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Macro for Looping for Criteria Checking

By the way, I do not think you will ever see "d" as a result, if it is blank,
then it will display "e", otherwise it is not blank and the contents will be
interpreted as a value and the =1, <1 and 1 tests will capture it.

"FARAZ QURESHI" wrote:

Can some1 pls give me an idea of how to design a simple "4" step looping
structure macro e.g.

If(A1=1,"a",if(a1<1,"b",if(a11,"c",if(not(isblank (a1)),"d","e"))))

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,651
Default Macro for Looping for Criteria Checking

Before you think about macros, you'll need to sort out your IF logic.

After you've tested for =1 and <1, you don't need to test for 1, as that's
all it can be (so you can't get to d or e).
Also, if you want to test for blanks, you'll need to do that before you
check the values; a blank will currently give a b output, as blank is less
than 1.
--
David Biddulph

"FARAZ QURESHI" wrote in message
...
Can some1 pls give me an idea of how to design a simple "4" step looping
structure macro e.g.

If(A1=1,"a",if(a1<1,"b",if(a11,"c",if(not(isblank (a1)),"d","e"))))



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Macro for Looping for Criteria Checking

Thanx David & JLatham,

But it was actually an example only.

Problem is that I have actually more than 20 criterias to be checked and I
have come to know that I won't be allowed to insert more than 7 nested
functions.
I don't think there would be any other wayout but a looping macro.

Please guide me in respect of how to write up such a macro to check the
criterias like , <, =, < and isblank. I would also appreciate if you would
guide me as to how a conditional formatting may also be added upon the
criteria not being met.

Lets have another example like:

How to:

Have Cell B1 be Red If A1<0;
Have Cell B1 be Bold If A10;
Have Cell B1 be Underline If A1=0;
Have Cell B1 be Italic If A1<0; or
Have Cell B1 be showing "X" If A1 is blank;

"David Biddulph" wrote:

Before you think about macros, you'll need to sort out your IF logic.

After you've tested for =1 and <1, you don't need to test for 1, as that's
all it can be (so you can't get to d or e).
Also, if you want to test for blanks, you'll need to do that before you
check the values; a blank will currently give a b output, as blank is less
than 1.
--
David Biddulph

"FARAZ QURESHI" wrote in message
...
Can some1 pls give me an idea of how to design a simple "4" step looping
structure macro e.g.

If(A1=1,"a",if(a1<1,"b",if(a11,"c",if(not(isblank (a1)),"d","e"))))






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Macro for Looping for Criteria Checking

I'll show a simple, one cell case using the Worksheet_Change() event to deal
with your problem. To insert the code below, right-click on the worksheet's
name tab and choose [View Code] from the list and put the code into the
module that appears in the Visual Basic editor. This shows changes to B1
being made in response to changes in value being made in A1
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$A$1" Then
Exit Sub
End If
'same as ISBLANK:
If IsEmpty(Target) Then
Range("B1") = "X"
Exit Sub
End If
'start these tests with
'the smallest limit and
'work upward in value
'first reset any previous results
Range("B1").Interior.ColorIndex = xlNone
With Range("B1").Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Bold = False
.Italic = False
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

Select Case Target.Value
Case Is = 0
'underline text
Range("B1").Font.Underline = xlUnderlineStyleSingle
Case Is < -20
Range("B1").Font.Underline = xlUnderlineStyleSingle
Range("B1").Interior.ColorIndex = vbRed
Case Is < -10
Range("B1").Font.Underline = xlUnderlineStyleSingle
Range("B1").Interior.ColorIndex = vbYellow
Case Is < 0
Range("B1").Interior.ColorIndex = vbRed
Case Is < 10
Range("B1").Font.Bold = True ' BOLD
Range("B1").Font.Italic = True
Case Else
'any left over condition, or
'does not meet any criteria
'you do not have to have any
'code in this section
End Select
End Sub



"FARAZ QURESHI" wrote:

Thanx David & JLatham,

But it was actually an example only.

Problem is that I have actually more than 20 criterias to be checked and I
have come to know that I won't be allowed to insert more than 7 nested
functions.
I don't think there would be any other wayout but a looping macro.

Please guide me in respect of how to write up such a macro to check the
criterias like , <, =, < and isblank. I would also appreciate if you would
guide me as to how a conditional formatting may also be added upon the
criteria not being met.

Lets have another example like:

How to:

Have Cell B1 be Red If A1<0;
Have Cell B1 be Bold If A10;
Have Cell B1 be Underline If A1=0;
Have Cell B1 be Italic If A1<0; or
Have Cell B1 be showing "X" If A1 is blank;

"David Biddulph" wrote:

Before you think about macros, you'll need to sort out your IF logic.

After you've tested for =1 and <1, you don't need to test for 1, as that's
all it can be (so you can't get to d or e).
Also, if you want to test for blanks, you'll need to do that before you
check the values; a blank will currently give a b output, as blank is less
than 1.
--
David Biddulph

"FARAZ QURESHI" wrote in message
...
Can some1 pls give me an idea of how to design a simple "4" step looping
structure macro e.g.

If(A1=1,"a",if(a1<1,"b",if(a11,"c",if(not(isblank (a1)),"d","e"))))




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
Macro looping endlessly Sandy Excel Worksheet Functions 6 May 10th 07 03:48 PM
Looping macro RK Excel Worksheet Functions 2 December 12th 06 11:29 PM
Looping a macro Sony Excel Discussion (Misc queries) 3 October 30th 06 11:52 AM
Macro looping problem. [email protected] Excel Discussion (Misc queries) 8 October 26th 06 02:44 PM
Looping Macro to Find and Mark Big Tony New Users to Excel 8 January 26th 05 09:07 PM


All times are GMT +1. The time now is 11:15 PM.

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

About Us

"It's about Microsoft Excel"