Solved

Conditional Statements

Posted on 2002-04-21
7
152 Views
Last Modified: 2010-05-02
I am trying to figure out how to set up a script that will first check cell a14 and a21.  Basically, if a14 is between 5000 to 2000 or a21 is 030 to 020 then cell z14 will insert the word "blue". The hard part is that in cell a21 i have text letters before that number for example "ced030" what i need is to only evaluate that number in a21 when the first three letters equal aaa or bbb.  For example if a21 equal ced030 it will not evaluate the 030 in that cell.  But if it has aaa030, then it will evaluate the 030, which meets the criteria above and will insert the word "blue" into cell z14.  Thanks For the help
0
Comment
Question by:stormhunter2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6957803
Hi Stormhunter2000,

you can use this formula in Z14

=IF(AND(A14>=2000,A14<=5000,OR(LEFT(A21,3)="aaa",LEFT(A21,3)="bbb"),(AND(VALUE(RIGHT(A21,3))>=20,VALUE(RIGHT(A21,3))<=30))),"blue","")

HTH:O)Bruintje
0
 
LVL 1

Expert Comment

by:alfanhendro
ID: 6958690
Bruintje, did you miss some part there?
I think it's supposed to be like this.

=IF(OR(AND(A14>=2000,A14<=5000),OR(LEFT(A21,4)="aaa0",LEFT(A21,4)="bbb0"), (IF(ISNUMBER(MID(A21,5,2)),(AND(VALUE(MID(A21,5,2))>=20,VALUE(MID(A21,5,2))<=30)),FALSE ))),"blue","")

Regards
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6958879
Hi alfanhendro, did you test both?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:stormhunter2000
ID: 6958981
How would i write this in vba.
0
 
LVL 44

Accepted Solution

by:
bruintje earned 40 total points
ID: 6959027
OK VBA then

-insert a new module in your workbook
-paste this code

Public Sub CheckValuesSimple()
  With ActiveSheet
    If (.Range("A14") >= 2000 And .Range("A14") <= 5000) Then
      If (Left(.Range("A21"), 3) = "aaa" Or (Left(.Range("A21"), 3) = "bbb")) Then
        If (Val(Right(Range("A21"), 3)) >= 20 And Val(Right(Range("A21"), 3)) <= 30) Then
          .Range("Z14") = "blue"
        End If
      End If
    End If
  End With
End Sub

-just run it

-a more generic solution

Public Sub CheckValuesDeluxe(ByVal rngOne As Range, _
                            ByVal rngTwo As Range, _
                            ByVal rngResult As Range)
  With ActiveSheet
    If (rngOne.Value >= 2000 And rngOne.Value <= 5000) Then
      If (Left(rngTwo.Value, 3) = "aaa" Or (Left(rngTwo.Value, 3) = "bbb")) Then
        If (Val(Right(rngTwo.Value, 3)) >= 20 And Val(Right(rngTwo.Value, 3)) <= 30) Then
          rngResult.Value = "blue"
        End If
      End If
    End If
End Sub

-if you put this function in a cell through the
-menu | insert | function |user definied | CheckValuesDeluxe
-ask for the first range > A14 in your sample
-ask for the second range > A21 in your sample
-ask for the result range > z14 in your sample

HTH:O)Bruintje
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7660612
Hi stormhunter2000,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept bruintje's comment(s) as an answer.

stormhunter2000, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7755183
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 393
VBA/SQL - Connect to SQL server and pull data 4 151
Automatic Email Reminder 4 94
RUNRMTCMD from AS/400 13 129
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question