473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is there an AND IF Function

I have the following code, but I require all 3 IF's to work if necessary. Can anyone help with this or offer me some advice on similar code. I do have more IF functions following this code though

If Range("G13") = 1 Then
Sheets("Price Sheet").Select
Range("B10") = "Master"
Range("D10") = "M"

AND IF?

If Range("H13") = 1 Then
Sheets("Price Sheet").Select
Range("B11") = "Slave"
Range("D11") = "M"

AND IF?

If Range("I13") = 1 Then
Sheets("Price Sheet").Select
Range("B12") = "Outlet"
Range("D12") = "M"

End If
Dec 5 '06 #1
4 2421
Not sure what you mean. There are only two ways to execute multiple if statements. You can make each if/end if follow on after the previous one as in the first example I gave in the reply to your previous post or you can nest if statements using the ELSE /IF construct I gave as the second example.

However you can use AND and OR logic in the if clause itself. If you needed all three ranges to be true before you executed your code you could do it this wayr

[code]

if Range("G13") = 1 AND Range("H13") = 1 AND Range("I13") = 1Then
Sheets("Price Sheet").Select
Range("B10") = "Master"
Range("D10") = "M"
end if

[code]

however from your code it looks like the first example I gave you in my previous response is what you want.
Dec 5 '06 #2
I have the following code, but I require all 3 IF's to work if necessary. Can anyone help with this or offer me some advice on similar code. I do have more IF functions following this code though

If Range("G13") = 1 Then
Sheets("Price Sheet").Select
Range("B10") = "Master"
Range("D10") = "M"

AND IF?

If Range("H13") = 1 Then
Sheets("Price Sheet").Select
Range("B11") = "Slave"
Range("D11") = "M"

AND IF?

If Range("I13") = 1 Then
Sheets("Price Sheet").Select
Range("B12") = "Outlet"
Range("D12") = "M"

End If

*****

hi nickwright

why don't you use a select case structure? if you have arange of if statements
that are the same except for the value you set it to or that it already has then
a select case statement will save you a lot of time and work...it also makes
your code more readable.

something like this (note: i have not tested this. this is only an example)

Expand|Select|Wrap|Line Numbers
  1. if Range("G13") = 1 then a$ = "G13"
  2. if Range("H13") = 1 then a$ = "H13"
  3. if Range("I13") = 1 then a$ = "I13"
  4.  
  5. select case a$
  6.  
  7.    case "G13"
  8.  
  9.       Sheets("Price Sheet").Select
  10.       Range("B10") = "Master"
  11.       Range("D10") = "M"
  12.  
  13.    case "H13"
  14.  
  15.       Sheets("Price Sheet").Select
  16.       Range("B11") = "Slave"
  17.       Range("D11") = "M"
  18.  
  19.    case "I13"
  20.  
  21.      Sheets("Price Sheet").Select
  22.      Range("B12") = "Outlet"
  23.      Range("D12") = "M"
  24.  
  25.    case else
  26.  
  27.    'Code for action to take if none of the above is true
  28.  
  29. end select
Hope this will be of some help
Spider1916

******
Dec 5 '06 #3
willakawill
1,646 1GB
*****

hi nickwright

why don't you use a select case structure? if you have arange of if statements
that are the same except for the value you set it to or that it already has then
a select case statement will save you a lot of time and work...it also makes
your code more readable.

something like this (note: i have not tested this. this is only an example)

Expand|Select|Wrap|Line Numbers
  1. if Range("G13") = 1 then a$ = "G13"
  2. if Range("H13") = 1 then a$ = "H13"
  3. if Range("I13") = 1 then a$ = "I13"
  4.  
  5. select case a$
  6.  
  7.    case "G13"
  8.  
  9.       Sheets("Price Sheet").Select
  10.       Range("B10") = "Master"
  11.       Range("D10") = "M"
  12.  
  13.    case "H13"
  14.  
  15.       Sheets("Price Sheet").Select
  16.       Range("B11") = "Slave"
  17.       Range("D11") = "M"
  18.  
  19.    case "I13"
  20.  
  21.      Sheets("Price Sheet").Select
  22.      Range("B12") = "Outlet"
  23.      Range("D12") = "M"
  24.  
  25.    case else
  26.  
  27.    'Code for action to take if none of the above is true
  28.  
  29. end select
Hope this will be of some help
Spider1916

******
The select statement is a multibple elseif construction and only the first case that matches will be executed. The rest will be skipped.


Nickwright can you put your if statement in an english language form? e.g.

if there are ten tomatoes then I would like to use the large bowl for salad and while we are at it why not fill the spare jug with flowers unless blah blah blah..

I have a sneaky suspicion that you are looking at a nested if statement to solve this one :)
Dec 5 '06 #4
Killer42
8,435 Expert 8TB
...I have a sneaky suspicion that you are looking at a nested if statement to solve this one :)
I'm inclined to agree. Probably something like...
Expand|Select|Wrap|Line Numbers
  1. If Range("G13") = 1 Then
  2.   Sheets("Price Sheet").Select
  3.   Range("B10") = "Master"
  4.   Range("D10") = "M"
  5.   If Range("H13") = 1 Then
  6.     Sheets("Price Sheet").Select
  7.     Range("B11") = "Slave"
  8.     Range("D11") = "M"
  9.     If Range("I13") = 1 Then
  10.       Sheets("Price Sheet").Select
  11.       Range("B12") = "Outlet"
  12.       Range("D12") = "M"
  13.     End If
  14.   End If
  15. End If
  16.  
Dec 6 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.