Check Multiple Conditions In Loop

Oct 22, 2009

I want to vary a for next loop, depending on the value of a variable (y). Is there a way of doing this without repeating code as in the example?


If y = 1 Then
For x = 1 To 100
' lengthy code changes Cells(x,1) characteristics
Next x
ElseIf y = 2 Then
For x = 101 To 200
'lengthy code changes Cells(x,1) characteristics
Next x
ElseIf y = 3 Then
For x = 201 To 300
'lengthy code changes Cells(x,1) characteristics
Next x
End If

View 9 Replies


ADVERTISEMENT

Macro Loop To Check Several Conditions And With Variable Increments

Oct 20, 2006

Excel file attached! I need a macro to do the following:

Start with cell F4 and read the increment value from cell C4. Then add this with F3 and display the result. Continue with the same increment until it reaches the value equal to cell B4. Then read the increment from cell C5 and do the same until value equals cell B5. Repeat the same step until it reach the value equals B7. I did manually in the column F4 to F28. Moreover, the cell increment will change according to the variable in A2. In this case it is 25 and got 25 values to fill the column R.

View 8 Replies View Related

VBA Do While Loop With Multiple Conditions

Jan 28, 2009

I'm having some problems getting a simple Do While loop to run. Essentially I'm trying to get it to run as long as one of two conditions is met, so I used an Or function in the loop condition. This then produces the "Run time error 1004: Application defined or Object defined error" error on that line.

I'm certain my syntax for the two conditions is correct (one is a simple check value in a cell, the other is check the value of a VBA variable) so it would appear the error is caused by the inclusion of the Or function. So I guess my question is this, have I done something wrong? If so what and if possible why is what I did wrong (I like to understand these things)? Is this something that has to be done in a different way or even is it something that cannot be done? I'm using excel 2003 on XP SP3.

View 5 Replies View Related

Nested If's Or How To Check Multiple Conditions In A Row

Jul 14, 2009

I have the data in this form

YYY
NYY
NYY
NNY
NYY
NNY
NYY
NYY
NYY
NYY
YNN
NNY
NNN
NYY

The output should check two conditions. If all three columns are "Y" then it should return value "Y". If any two columns are "Y" then it should return value "Y". or else it should return "N". Then the output should look like this.... The output column is colored in Red..........

View 5 Replies View Related

VBA Code. Check Multiple Conditions

Jul 22, 2007

I want to create a user form in excel that auto calcs the discount depending on customer type and no. of books purchased. There are two types of customer’s one individual and the other schools, library etc. The discounts are below

More than 50 books - 30%
25 - 49 - 20%
15 - 24 - 15%
5 - 14 - 10%
<5 - 5%

Individual
>25 - 25%
5 - 24 - 15%
<5 - 0%

I have created a form with option and text boxes to capture data but am really struggling with this as in my head I understand a set calculation will need to take place once relevant conditions are met but am really struggling to put it into code (yes I am new to this).

View 2 Replies View Related

Check Conditions In Multiple Cells With One Cell

May 22, 2006

=AND($AE$2:$AE$10<=$F$2:$F$2000;$AE$2:$AE$10>=$E$2:$E$2000) With this I am checking for conditions to be true or false

Lets say I am checking AND(AE2 <= F2 ; AE2>=E2) this tells me if date in cell
AE2 is smaller or equal to Cell F2, but how can I set this fromula to check if all the cells from F2 to F1000 are equal to AE2 so If I write date into Cell AE2 it checks all dates from F2 to F1000 and check if condition is true or false
(and if I write date in cell AE3 it should check all the dates from F2:F1000, if date in AE3 is in this range)

View 9 Replies View Related

VBA Check If A Cell Is Empty - Move 7 Cells Over And Check Again (Loop)

Aug 10, 2012

I have data in Row 53 that spans 7 columns, but stays in the same row. I want to design a loop to select every 7th cell in that row and check if it is empty. If not, add onto a "counter" then display the final number of occupied cells (the value of the counter) at the end. This is what I have so far, but I get all sorts of errors.

Code:
Sub Tester()

Dim WB As Workbook
Dim WS As Worksheets
Dim modCounter As Long
Dim Cell As Range

Set WB = Workbook("Transverse Series.xlsm")
Set WS = WB.Sheets(BM18)

[Code] ......

View 1 Replies View Related

Check 2 Conditions With IF AND OR

Nov 8, 2006

i am trying to create what is probably a simple If statement for a worksheet formula i want to check to see if one of two cells have the text specified if so then the cell value is A4 from another sheet if not the cell containing the formula should be blank, something like below

=If(B1="on" Or D1="on",Sheet2!A4,"")

I also need this kind of formula with the AND operator, something like

=If(B1="off" And D1="off",Sheet2!A4,"")

View 5 Replies View Related

Check Cell For 2 Conditions

Sep 30, 2007

I have a sheet here whereby if Bor No = 1, then total incurred should return as incurred. But if BOR No is more than 1, then the total incurred should sum up seq 1 and 2 of incurred. Bear in mind that seq no could be up to 4, 5, 6.. and it's not fix. But if BOR No = 0 or NULL, then total incurred should equal to "0"

View 5 Replies View Related

Check Sum Then More IF Function Conditions

Jun 22, 2008

=IF(H10=0,IF((R10-I10)>$AH$1,(R10-I10),0),IF((R10-N10)>$AH$1,(R10-N10),0))

I have a small issue with the formula above. Basically the sheet is used to input start and end time of shifts and create breaks and lunches accordingly. The formula above resides in column S. Basically it warns us if the end of the shift is over 4.00 hrs past the end of the last lunches. A shift can have no lunch, one lunch or two lunches. H10 would be the start of the first lunch, R10 is the end of shift, I10 is the end of the first lunch, AH1 = 4:00 or 4:00:00 AM, N10 is the end of the second lunch.

What happens is that if there is no lunch given in cells H, I, M, N or in this case H, I, N then I get a strange number. For instance, I put in 6:00 for the start time [E10] (actually we input military time and the result is displayed in AM or PM) and the end time as 8:00, then I get a result of 8:00 in the S column [titled +4hrs warning). 6:00 to 9:00 results in 9.00 hrs., etc, When we input a six hour shift, a lunch is automatically starts in H10 and ends in I10. Once this begins, the formula works correctly.

View 4 Replies View Related

VBA Format Conditions For Next Loop

Nov 19, 2012

Problem: Placing a With/End With for FormatConditions in a For/Next loop isn't applying the conditional formatting.

Information:
- I have a stats section that has months as the column headers with totals at the end (used as a VLOOKUP table)
- Each column needs the conditional formatting separately
- The columns are static, but the rows are variable
- Taking it out of the loop and coding each loop individually works perfectly

The problem code:

finalRowTable = Cells(Rows.Count, 12).End(xlUp).Row
For i = 13 To 38
With Range(i & "11:" & i & finalRowTable)
.FormatConditions.Delete
.FormatConditions.AddTop10
.FormatConditions(1).TopBottom = xlTop10Top
.FormatConditions(1).Rank = 1
.FormatConditions(1).Percent = False
.FormatConditions(1).Interior.Color = 5296274
End With
Next i

I checked after running it and it doesn't show up in the Manage Rules Conditional Formatting

Code that works without loop:
Code:
With Range("N11:N" & finalRowTable)
.FormatConditions.Delete
.FormatConditions.AddTop10
.FormatConditions(1).TopBottom = xlTop10Top
.FormatConditions(1).Rank = 1
.FormatConditions(1).Percent = False
.FormatConditions(1).Interior.Color = 5296274
End With

I've been playing with excel VBA for a few months now, so it's probably something simple.

View 4 Replies View Related

Check Four Conditions Return TRUE Or FALSE

Nov 16, 2009

I have several rows with numbers that is either 0, a balance or a text like n/a. I need a formula that return true if all are 0 or contain n/a. If there is one balance shall it be false. Any suggestion? See example:

View 6 Replies View Related

For Loop (check The Value In Column)

Mar 18, 2009

how to write a for loop for this coding.
considering x as row,
i want to check the value in column1 for n rows.

View 7 Replies View Related

Loop Through Multiple Files And Call Macros (but Unable To Loop)

May 14, 2014

Macro which loops through a number of files and calls the same macro in each of them. Unfortunately when I add "Application.Run..." to the code, it no longer loops through the process and instead stops after updating the first file in the loop. If I remove the "Application.Run..." code and add any other code, the loop works fine and it continues through the process repeating all the steps for each file found.

Why it stops after one file when using "Application.Run..." to call the macros?

NB I have a list of path and file names starting in row 8 of columns A and C. Each file in the list has a macro called UpdateS1 and promoupdate1.

Sub C_Run_Loop_Macro()
Dim lastRow As Long
Dim i As Long

[Code]....

View 4 Replies View Related

Countif (check The Data For The Following Conditions, If It Meets The Crirteria Then Place A 1 In Columns)

Aug 22, 2009

the traditional count if statement doesnt return what I need. I have an array of values that need to be checked.

Column: A B C D E
Data: .25 .49 .18 (Criteria 1 Result) (Criteria 2 Result)

What I need to do is check the data for the following conditions and if it meets the crirteria I need excel to place a 1 in column D or E.

Criteria 1
If any of the coulmn data contains a value less than .5 I need a 1 placed in column D

Criteria 2
If any of the column data contains a value greater than .5 but less than 1.0, I need a 1 placed in Column E. I tried using an IF/ Count If statement, but cant seem to get it to return the result I need.

View 5 Replies View Related

Loop And Value Enter Check - Getting Errors?

Mar 20, 2014

I have a calculation to do (see cell Q4 on image attached) where the variables to enter are s1,g1, s2,g2 etc.... In some cases I will only have s1 and g1 and the rest (s2,g2 etc...) will be zeros. As you can guess I cannot put 0's because I will get errors, however I can not either put a empty cell.

So this is why I want to create my first subroutine, where the variables will be from F5 to P5 and be able to drag down the formula to compute the same calculation for the lower rows.

View 7 Replies View Related

Do...while Loop: Check Until So Many Cells Have Been Marked Red

Jan 25, 2007

i'm having a bit of a issue with a do while loop. It might just be my complete lack of understanding, but i'll briefly explain what I am doing before I show you the code. I am marking cells with what I consider an invalid type for that cell red. Well unfortunatley in some sheets the number of invalid types is so high the macro crashes. So my bright idea was to inclose the check statment into a do while loop, that will only check until so many cells have been marked red. So I created a public variable, assigned it a value of 1. I then assigned the macro that marks the cell red to also take y and add 1. So in theory (mind you what I take for theroy might be in my head) it should only run until the paramaters of the do while are met which in this case are do while y < 20.

y = 1
Do While y < 20
Set MyRange = Intersect(Columns(7), ActiveSheet.UsedRange)
For Each r In MyRange
CheckDate
Next r
Loop

That is the snippet from the program calling the function, and here is the function

Public Function CheckDate()
If IsDate(r.Cells) = False And IsEmpty(r.Cells) = False Then
r.Select
MarkDate
y = y + 1
End If
If r.Cells < 1 / 1 / 1910 And IsEmpty(r.Cells) = False Then
r.Select
MarkDate
y = y + 1
End If
End Function

what i'm doing wrong here? Oh and y is assinged as a public varaible, integer data type.

View 5 Replies View Related

Loop Macro To Check If Cells Not Empty

Jun 27, 2014

Column 'N' and 'O' will be used for inputting information and will never be hidden

Column 'E' through 'F' hold information, however the user will have hidden all but one of columns 'E' through 'F' before running macro

Once the user initiates the macro, the program will detect which column in 'E' through 'F' is not hidden

The macro will then start at row one of the unhidden column and loop down looking for the text 'Req' (not including ' )

If the loop finds 'Req' it will search in column 'N' of the same row for any data at all
If it finds data in column 'N' for that particular row, it will check column 'O' of that same row for any data at all
If it finds data in column 'O' also, then all 3 parameters have been met

The loop should continue checking for these 3 items through row 500

If the loop determines that for every 'Req' found in the unhidden row there is data in the corresponding column 'N' and 'O' a message will appear that says 'Checklist Complete"

Upon closing the message box, the file should save and then exit

If the loop determines that for every 'Req' found in the unhidden row, there is not always data present in column 'N' and 'O' the message box should appear and say 'Checklist Incomplete'

In the same message box, it should provide a list under 'Checklist Incomplete' that provides the text found in column 'D' for each row where it failed the test of having 'Req' in the unhidden row and data at all in column 'N' and 'O'

That last part will give the user a tool to see where they might have forgotton to enter data.

View 3 Replies View Related

Loop Through Set Of Files And Check If File Doesn't Exist?

Feb 11, 2014

My problem is that I want to loop through a directory that contains csv files. The directory is dynamic so everytime could be a different number of files inside. I want the loop to go through each file and check if that file exists. If it doesn't to print a message that this specific files doesn't exist. Until now I got the following code:

[Code] .........

I guess I should somehow place the counter j inside the Dir path in order to check if everytime time the file[j] exists?

View 6 Replies View Related

Excel 2010 :: Loop Through To Check For All Filenames In Folder And If Then?

Dec 22, 2013

getting a function working within Excel 2010. What I'm trying to do is to first look in a specific directory and loop through each foldername then check to see if the foldername exists in column B of my worksheet. If the foldername exists then check Column E of the same row for a specific value ("assigned") and then make sure column F of the same row has no picture inside the cell. If those three things exist (column B foldername and column E "assigned" and no picture in column F), then add a picture to column F of the same row as the foldername with a hyperlink to a filename of "notes.one" in that specific folder. Then just loop through each foldername in the specific directory until all foldernames have been checked.

View 1 Replies View Related

Count Unique Logs With Multiple Conditions Of Multiple Sheets

Oct 8, 2007

I've got no clue about all this, but I've had to get specific formula examples and fill in the blanks in order for my timesheet to work. There's just one final problem if somebody could please help.

This is a timesheet for a 5 day work week. I need to count the number of unique log numbers for a specific activity. The log numbers counted must be unique across the entire week, not just for each day, which means I want the formula to count the unique log numbers across multiple sheets.

The formula also has multiple conditions. I got 2 columns. The first part of the formula needs to verify a word, say, "split" and if it does it checks the adjacent cell for a unique log number. If both arguments are true, it counts the log as 1 unit.

Here is a working formula for only one page.
=COUNT(IF(D4:D29="split",IF(FREQUENCY(C4:C28,C4:C28)>0,1,)))

Here's 2 problems with this formula:
1. I will count if it encounters a blank cell in the Log numbers the first time (which will happen as not every activity we do has a log#), but it will stop counting if it encounters a second blank cell.

2. I don't know how to make it work across several sheets.

This is an alternate formula which works and skips the blank cells, but I don't know how to add the multiple condition of "split" and to have it work across multiple sheets. I just copied it Microsoft. As I said, I don't understand it, I just fill in the blanks.

SUM(IF(FREQUENCY(IF(LEN(C4:C29)>0,MATCH(C4:C29,C4:C29,0),""), IF(LEN(C4:C29)>0,MATCH(C4:C29,C4:C29,0),""))>0,1))

View 11 Replies View Related

Remove Multiple Data By Multiple Conditions?

Aug 21, 2009

1. I have 4 columns (let's say D,E,I,J);

D E I J
Account1 Sum1 Account2 Sum2
151 93,79 BF2479 30,00
1476757 93,79 BF7 22,00
BF2479 30,00 151 93,79
86041 84,03 23235 30,00
534 6608,45

2. I need to clean the multiple identical data in the list by both Account no. and Sum (of course the list is much longer!) so that the list should look like this:

D E I J
Account1 Sum1 Account2 Sum2

1476757 93,79 BF7 22,00

86041 84,03 23235 30,00
534 6608,45

I must say that I am a beginner in Excel, so I tried to use this:

=IF(OR(E5=$J$5:$J$430);IF(INDEX($I$5:$I$430;MATCH(E5;$J$5:$J$430;FALSE);1)=D5;"";E5);E5)

for column E, and

=IF(OR(J5=$E$5:$E$452);IF(INDEX($D$5:$D$452;MATCH(J5;$E$5:$E$452;FALSE);1)=I5;"";J5);J5)

(which is reverse of the first one) for column J; (The ranges are the ones used in the real sheet), not for the ones in the example above!); The formula does seem to eliminate a dew unwanted data, but does not give me all the wanted results!

View 4 Replies View Related

How To Satisfy Multiple Conditions Using Multiple Criteria

Oct 16, 2009

I'm trying to divide my data into 6 different groups, based on 2 different criteria. First, I am not sure how to write the logical test to take 2 columns of data into consideration (using "&" and "AND" do not work; I am not sure what else to try), and second I can't figure out how to write the formula so that it can select from 1 of 6 conditions.

So, overall here is what I want:

If DL2=3 and CK2=1, then I want this to be labeled as '1'
If DL2=3 and CK2=2, 2
If DL2=1 and CK2=2, 3
If DL2=2 and CK2=2, 4
If DL2=1 and CK2=1, 5
If DL2=2 and CK2=1, 6

These 6 conditions cover all possible combinations of numbers in the two columns.

View 13 Replies View Related

Sum On Multiple Conditions In Multiple Columns

Nov 29, 2008

My data looks somewhat like this :

X Y Z
DOU Quarter Sum
0 Q1 = sum of 1's in Q1
1 Q1 = sum of 1's in Q2
1 Q2 = sum of 1's in Q3
0 Q2 = sum of 1's in Q4
1 Q3
1 Q1
1 Q4
0 Q2

A cell in the SUM column must contain the sum of 1's in column DOU if under column Quarter the value is Q1. Similarly for Q2, Q3 & Q4 if only the corresponding value under DOU is 1.

Its like.. count the number of 1's per quarter and come up with the sum in 4 distinct cells for each quarter.. i.e. quarter-wise sum/count of 1s

View 9 Replies View Related

VBA Multiple IF Conditions

Aug 9, 2009

If ActiveCell.Value < -25 And ActiveCell.Offset(-2, 0).Value < -25 And ActiveCell.Offset(-3, 0).Value < -25 Then
Range("C4").Select
End If
End Sub

I am looking to do something similar on excel 07 as follows:
Range("O16").Select
IF ActiveCell.Offset(0,-1)Value ="1" And ActiveCell.Offset(0,-2).Value = "1" Then
ActiveCell.Value = "1"

Compile error expected: Then or GoTo At the First value (which I have highlighted in red)

Also would like the If formula to repeat for range O16:O36.

View 9 Replies View Related

Sum With Multiple Conditions

Jan 29, 2007

see attached workbook.

I need to create a conditional sum in the report tab in the yellow cells that will sum all the values from the list sheet, based on the following conditions.

1) The name is in the list
2) The code in the list is one from the codes tab.

I saw somewhere that I need to put an 'OR' statement in the conditional sum but I can't get it work. It seems to add up values for the code 'HOLIDAY' and I don't want it to.

View 3 Replies View Related

If Formula Using Multiple Conditions?

Nov 29, 2013

I cant seem to rack my brain around how to go about making a formula in order to achieve my desired effect using the IF Formula. The data is as follows:

Worker Status %
S1 75% and higher
S2 42.8571% -74.9999%
SH Anything below 42.8571%

My sheet pulls the workers status from a preset data table, lets say S2 for Joe. I want the cell beside his status to compare what his percentage is and display what the status should be (based on the conditions of the above table). If hes working 73% it will turn up S2 and I can compare the value from the table and the value generated based on his working percentage (I would use conditional formatting to color the cell red or green to indicate if it matches or not.)

View 4 Replies View Related

Vlookup And Multiple Conditions?

Dec 17, 2013

Is VLOOKUP suitable for if one wants to lookup a value from a defined range based on two assumptions?

Enclosed is an example file.

I want to lookup the values in sheet1 in the defined range in sheet2 and write enclosure and density to sheet 1

what method to use?

nicolaiBook1.xlsx

View 6 Replies View Related

Another IF Function With Multiple Conditions?

Mar 1, 2014

My spreadsheet looks like this:

Column A: Individual
Column B: Not used in formula
Column C: Not used in formula
Column D: Location
Column E: Duration in Minutes
Column F: Pay (Column E)*(Column G)
Column G: Formula

(simplified version listed below)

[Code].....

To be clear of what I'm trying to achieve:

When in location 1 & 2 (Column D), the pay for each individual is a different rate depending on the duration in Column E, but when in Location 3, the rate is consistent no matter what the duration.

My question is:

How do account for individuals who aren't individual1? That is, my understanding of the above formula is that I need to list each individual that will appear in Column A for it to work. What if I just want to apply the above to individual1, but apply some other calculations to all other individuals?

I had tried adding these lines (with their corresponding closed-parentheses at the end)

[Code]....

But it doesn't work. I'm guessing it's some sort of OR, but I don't yet grasp how.

I should note that my formulas are all on one line in my spreadsheet, I just have them on separate lines to make it easier to find my way around.

View 14 Replies View Related

How To Use Count With Multiple Conditions

Aug 4, 2005

I have a table in Excel:

The first row is time in years.

The second row is method name,say,"A","B","C".

I want to count the number when the time is less than 5 years AND "A"
method is adopted.

I tried this:
count(if(AND(C2:Z2<5,C3:Z3="A"),C2:Z2) but it didn't work.

how to revise the formula?

In the mean time, count(if(C2:Z2<5,C2:Z2))worked as well as
countif(C2:Z2,"<5")

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved