Loop Sheets, Find Value & Test Condition

Dec 5, 2006

I want to search a column, from A30 moving up to A10 for the first value in excess of 0.

Having found the value the search stops and I want to select the cell next to it in B column.

Then I want to check if a value in B column exists. If no value exists I want to enter a fixed value from another sheet.

If a value does exist I want to take no action and move on to Column C to repeat the checking process for columns C and D.

Then I want to move to the next spreadsheet and repeat the process.

The code I have written so far is below and I just can't get it to work.

I have attached a spreadsheet to illustrate the problem.

Sub Closingdata()

Dim a As Integer
Dim b As Integer
Dim rngOutput As Range
Dim shtTemp As Worksheet
Dim vntName As Variant

For Each vntName In Array("sheet1", "sheet2")
Set shtTemp = Worksheets(vntName)

shtTemp.Select
shtTemp.Range("a30").Select
Do Until ActiveCell.Value > 0
If ActiveCell.Value > 0 Then
ActiveCell.Select
Exit Do
End If

View 7 Replies


ADVERTISEMENT

Find Value, Loop Through 2 Sheets And Copy Headers

Jan 22, 2010

I am putting in search items and running a macro to find the items on 'physical servers' WS, copying the header in that WS and the entire line the match appears on, though I cannot get it to do this.... it is really causing me stress

Then next part that is working is the items that return false are showing up on the results page - this is expected and what i want it to continue to do.

What I cant seem to work out also is how to run the search on the 'Virtual Server' WS also and return the results to the results WS as just like the 'physical servers' WS.

I have included some dummy data + code + the expected result on the 'Server Results' WS.

Hope you all can work out a way to make it work.

View 14 Replies View Related

Code To Find And Offset Works On First Sheet But Won't Loop To Other Sheets

Mar 5, 2009

I have this code attached to a button on the first sheet of a workbook with hundreds of sheets.

it is suposed to look for a cell that contains "SAY:" and then move one column to the right and make it a zero. It works on the first sheet but not on any other sheet.

View 7 Replies View Related

Multi Condition Date Cell Test For Month & Year

May 18, 2009

Please refer to attached Sinking Fund worksheet. have managed to solve most of it. Just need to figure out how to match the periods out. My requirements are on the worksheet.
1. To get the schedule on sheet 1 to stop calculating further once it has reached the actual number of payment periods as shown in H12.
2. To get the interest calculation in sheet2 to stop once the actual number of payment periods as shown in sheet1 H12 is reached.

View 3 Replies View Related

Confirm True In Logical Test Using Find

Nov 9, 2009

I'm trying to use the following formula to verify if the "," is within a cell. Something is not right, because even for True conditions, I'm getting a False return. I think my True logical test is not written right.

View 3 Replies View Related

For Loop And If Condition

May 1, 2009

for each value in column "h" if value = "k"
then check the respective value in column "b" = null
loop should iterate for entire column
then print its null

View 9 Replies View Related

Test Two Cells And Set A Third Cell With Different Values Depending On Test Results

Aug 21, 2013

I am trying to determine Long Term Gain (LTG,) Long Term Loss (LTL,) Short Term Gain (STG,) Short term Loss (STL,) or No Loss nor Gain (NGL)testing two cells (A1 and B1)and setting a third cell (C1) to the text LTG, LTL, STG, STL, or NGL depending on the results of testing cells A1 and B1.

A1 represent a number of years and B1 represent gains or losses (negative)in dolars.

The way I see the logic is as follows:

If cell A1 or cell B1 are either one of them equal to 0, then it is neither a Gain nor a Loss (NGL.)

If cell A1 is greater than or equal to 1, then it is Long Term; else, if A1 is greater than 0 and less than 1, then it is Short Term.

On the other hand, if cell B1 is greater than 0, then it is a Gain; if B1 is less than 0 (a negative number,) then, it is a Loss.

I need to find (if it is posible in Excel) one formula to test the two cells for posible outcomes:

If A1 = 0 then C1 = NGL
If B1 = 0 then C1 = NGL
If A1 >= 1 and B1 > 0 the C1 = LTG.
If A1 >= 1 and B1 < 0 the C1 = LTL.
If A1 < 1 and B1 > 0 then C1 = STG
If A1 < 1 and B1 < 0 then C1 = STL

View 3 Replies View Related

For Loop - Inserting Row If Certain Condition Met

Aug 29, 2013

Inserting a row. I have a for loop, and after a certain condition is met, add a row.

VB : Rows(i).Insert Shift:=xlDown

View 1 Replies View Related

While Loop Doesn't End On Condition

Jun 30, 2014

I'm trying to print the list of dates for the particular month . where the start date and end date is given by the user through user form.

I have written the below code to generate the dates. but the for loop still continues even when the start date is greater than the end date.

For example if i enter the startdate as 06/01/2014 and enddate as 06/30/2014. the for loop continues and displays date for all 40 days instead of stopping when the condition is met.

View 4 Replies View Related

Exit Loop When Condition Met

Nov 27, 2009

My code is meant to ensure a string in a cell begins with three letters and ends with 5 numbers. It seems to work, but how can I exit the loop and go to the message box once the boolean variable is set to true? I was hoping to avoid using labels. Also, I would appreciate any suggestions in compacting the code if possible, but without using CreateObjects".


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("h17")) Is Nothing Then Exit Sub

Dim Ls As String
Dim i As Integer, z As Integer
Dim MyString As String
Dim MyClVal As String: MyClVal = Target.Value
Dim MyBL As Boolean: MyBL = False

View 9 Replies View Related

Leave Loop When Condition Met

Dec 2, 2006

I am writing a very simple Do While loop where VBA searches for the first nonempty cell in a column starting from cell C3. The error I get is "Overflow". I suspect that when all cells are empty it goes down the column till the last cell, which is around 65,000. How can I put a restriction on this loop? I need the search to be restricted to range C3:C95, because my data ends in row 95. In other words, the code essentially should do this: go from cell C3 to cell C95 and search for the first nonempy cell in this range. When you find the first nonempty cell, assign name "x" to this first nonempty cell.

View 6 Replies View Related

Highlight Certain Cells Given If Loop Condition

Feb 14, 2013

I have a piece of code that basically performs a calculation and prints one value to a worksheet at the end. This code is part of a larger simulation model and by the end of the model this piece of code is executed thousands of times and thousands of values are printed to the worksheet. However, at the start of that piece of code there is an if statement which influences the end result. My question is, how to identify which end values were calculated using each method in the for loop.

For example would it be possible to highlight the cell (in which the value is printed) in red if the

VB:
num= 0

Part of the if statement was used and highlight the cell (in which the value is printed) in green if the

VB:
num= 1

Part of the if statement was used?

This would identify which values were calculated using each method.

VB:
'Change in Model set prior value
If ws1.Range("D" & Rows.count).End(xlUp).Row < 2 Then
num = 1
counter1 = counter1 + 1
sh1.Range("g3").Value = counter1

[Code] .....

View 1 Replies View Related

Delete Row And Loop Based On Condition

Jan 9, 2007

i have a set of data as below and wish to delete ENTIRE ROW if cell is the same but keep the first entry when code comes to it..ie in the data set below excel would keep first row and delete 2nd,3rd,5th, 6,7,8 and then go to next unique identifier which would be AU0000LIFHB3 this would not be deleted as it is unique the would proceed to AU300GPTC011. this process would then stop when no data was available

AU300AUS1019
AU300AUS1019
AU300AUS1019
AU0000LIFHB3
AU300AUS1019
AU300AUS1019
AU300AUS1019
AU300AUS1019
AU300AUS1050
AU300GPTC011
AU300GPTC011
AU300GPTC011
AU300GPTC011
AU300INTE018
AU0000LIFHB3
0
AU300SUNQ027

View 4 Replies View Related

Find, Meet Condition, Sum Range, Deduce, Find Next

Sep 23, 2007

i have spent 40 hours, and still didn't find a solution. Please help is need it!!
example:
i have to find all articles with same code (222). first one has Q =100 second one Q=250.
soled Q=150
(i am talking about 5000 rows, 400 different or same articles per month- 12 months)


columnA-----columnB---columnC
222 ----------100---------0
111-----------50
333-----------70
222----------200---------200
333---------- and so on
first i have to deduct from the first one it finds (max. till 0 ...it can not be negative) ....after finding another one it deducts the rest---it means 50
Is there any kind of formula with this possibility.
if it is poorly writen please let me know for more info.
i am not an expert in excell, but i have tried variations of sumif, vlookup functions, but i always get stuck deducting the whole Quantity from all of the same (222) articles .

View 9 Replies View Related

Start/Stop Loop Based On Condition/Criteria

Aug 31, 2006

I have a piece of code that put a check in all checkbox in column B from row 5 to row 50 but in column C, I have data from row 5 to 38. I want the macro to stop at row 38 in column B. When the cell in column C is empty stop putting checks in column B. How can I make this macro Check all checkbox down column B and stop when column C is empty. How do I add a loop to stop when the cell in column C is empty?

Private Sub CommandButton1_Click()
Dim CB As Variant
For Each CB In ActiveSheet.CheckBoxes
CB.Value = False
Next
End Sub.......

View 3 Replies View Related

Find Format: Find Method And Combine It With A Countif Or Loop

Feb 20, 2007

I'm trying to use this Find Method and combine it with a countif or loop. Something that will count a number of occurences of a unique type of character. I'm looking to find all "F" characters in Bold, Italic and Size 16. Here's my find code that I'm trying to use. I can get it to work by itself but not along with a countif or loop.

Sub count_4()
Dim r As Range
Set r = Range("A1:A6")
With Application.FindFormat.Font
.Bold = True
.Italic = True
.Size = 16
End With
r.Find(What:="F", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, searchformat:=True, MatchCase:=True).Activate
End Sub

View 4 Replies View Related

VBA To Extract Data From Sheets If It Match Condition

Nov 13, 2012

I wanted to extract the data from the sheets if it match condition.

In the sheet george, data is in the A9: AE500. in the B9:B500, there is date format (mm-yy).

In the H9:AD500, designed as checklist where update as "Y" if or nothing

I wanted to extract the data from this file to sheet Exctract if any of the cell in the H9:H500 not equal to "Y" and B9:B500 of sheet george is less than or equal to D2 of sheet Extract. in the sheet George, some row will be hidden, i wanted to bring the data from hidden rows also.

View 4 Replies View Related

Loop Through Sheets 2-4 Only?

Aug 2, 2012

How do I tell a loop command to stop after a certain number of sheets? The code below works for what I want to do but it saves all the sheets in my workbook bar the first one. I just want to save sheets 2, 3 & 4

Code:
Option Explicit
Sub mysaver()
Application.Calculation = xlManual
Dim counter As Integer
counter = 2
' counter is for the number of sheets in the workbook
Do While counter

View 1 Replies View Related

For Each Loop- How Can I Specify Which Sheets To Do This For And Then Loop Thru All Sheets To Do It

Apr 5, 2007

I think I need a For Each Loop, but I'm not sure. I want to collapse all grouping to the highest level for certain sheets in a book.

Sheets("sheet1").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1
Sheets("sheet2").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1
Sheets("sheet3").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1

How can I specify which sheets to do this for and then loop thru all sheets to do it?

View 9 Replies View Related

How Do I Loop Through Sheets

Mar 14, 2008

I want to perform an action on all but one of my worksheets. I've heard the array function can be used for this but I'm unfamiliar with its use.

View 9 Replies View Related

For Loop Through All Sheets

Apr 24, 2007

why this code does not work on all the sheets in the active workbook? Actually it just work on the current active worksheet.

Dim ws As Worksheet
ThisWorkbook.Activate
For Each ws In AtiveWorkbook
ws.Activate

code here

Next ws

View 4 Replies View Related

Using Condition IF With Find

Feb 1, 2010

The fuction works if the statement is found to be "True" but returns a value error
if the statement is "False". Anyone know the reason I'm getting a value error?

View 5 Replies View Related

Find Max With Condition

Apr 4, 2007

I need to look up a maximum value in a table depending on a condition. I have attached the spreadsheet. Basically, I need to find the maximum value for " Sum" column on sheet "Column Data" depending on the Coltype value on Column Summary. This should be returned to Sheet "Column summary"

For example, the formula should look in Cell A4 of column summary, see that Coltype is B, then look in column C of sheet column data and find the maximum value in column F:F of all the Coltype (column C:C) values that are of type B.

View 3 Replies View Related

Auto-populate Sheets Within One Workbook Based On Condition

Dec 20, 2012

I have a single registration sheet that lists names, contact information, and the class someone is in on a single sheet.

(Name, Number, Email, Class 1, Class 2)

I am hoping to automatically populate other sheets in my work book based on classes... essentially making automatically populated rosters. For example, everyone who has Math listed in either Class 1 or Class 2 would have their entire row (with contact information, etc) copied to the "Math" sheet.

View 2 Replies View Related

Populate New Sheet With Data From Multiple Sheets Given Condition?

Dec 16, 2011

I am trying to populate a blank sheet with data from multiple sheets given a certain condition.

Scenario: I have multiple columns on each sheet, but only three of interest to me. The first column has a header "Part ID", the second column header is "Description", the third column header is "QTY". I want to pull the data from all three columns to the new sheet when the QTY for that column IS NOT 0. The three columns of interest are always in Column A, B, and C.

The only thing that may make it tricky is that the data doesn't necessarily start on the first row of each sheet. For example, the headers for the first sheet are on row 17, and the headers for the second sheet are on row 5. So on and so forth...

View 3 Replies View Related

Hide Rows Based On Condition - Multiple Sheets

Mar 7, 2008

I want by using some code I've seen on this forum or using the macro writer and then tweaking the code. So with that said, I've written the attached code but I know there is probably an easier way to write it. It cycles through about 12 sheets using the same below code, but I didn't list that code.

Sub Hide_Rows()
Dim i As Integer
For i = 3 To 418
Sheets("AFA - UMBI").Select
If ActiveSheet. Range("b" & i).Value = "2008-2" Then
Rows(i & ":" & i).EntireRow.Hidden = True
ElseIf ActiveSheet.Range("b" & i).Value = "2008-3" Then
Rows(i & ":" & i).EntireRow.Hidden = True
ElseIf ActiveSheet.Range("b" & i).Value = "2008-4" Then
Rows(i & ":" & i).EntireRow.Hidden = True
ElseIf ActiveSheet.Range("b" & i).Value = "2009-1" Then
Rows(i & ":" & i).EntireRow.Hidden = True
ElseIf ActiveSheet.Range("b" & i).Value = "2009-2" Then
Rows(i & ":" & i).EntireRow.Hidden = True
ElseIf ActiveSheet.Range("b" & i).Value = "2009-3" Then
Rows(i & ":" & i).EntireRow.Hidden = True
ElseIf ActiveSheet.Range("b" & i).Value = "2009-4" Then
Rows(i & ":" & i).EntireRow.Hidden = True
End If
Next i
End Sub

View 7 Replies View Related

Delete Columns From All Sheets Based On Condition In X Workbooks

Mar 28, 2008

I am sure this is a very simple questions. I am using the below code to work on the worksheets on a workbook called "MF BANK EXPOSURE SUMMARY.xls" so far the code that I am using is:

Sub Commandbutton2()
Dim iCol As Long
Dim Isheet As Long
Dim Item As Worksheet
Set MFBANK = Workbooks("MF BANK EXPOSURE SUMMARY.xls")
For Each Item In MFBANK.Worksheets
With Item. Range("A1:T65536")
For iCol = .Column + .Columns.Count - 1 To 1 Step -1
If IsEmpty(.Cells(65536, iCol)) And IsEmpty(.Cells(1, iCol)) Then
If .Cells(65536, iCol).End(xlUp).Row = 1 Then .Columns(iCol).Delete
End If

Next iCol
End With
Next Item

End Sub

I would like to extend the code so that it works on the worksheets of two workbooks at the same time the one being the "MF BANK EXPOSURE SUMMARY.xls" and the other being "MF CP EXPOSURE SUMMARY.xls" .

View 3 Replies View Related

Loop Through All Sheets, PasteValues

Oct 28, 2008

the code for looping through ALL the sheets in a workbook, copying ALL the cells and pasting the values?

View 5 Replies View Related

Loop Sheets In More Than One Workbook

Jan 28, 2009

I have a small macro that searches the sheets in a workbook and sends the info (if qualifies) to a new workbook before saving that workbook using a name date time format for records.

I woud like this macro to be able to repeat action in 8 more selected workbooks in a folder.
Question - can I name the workbooks I want to search - and - can I search all 9 workbooks before the data sheet saves and names itself, limiting access.

View 13 Replies View Related

Loop Through All Sheets And Execute

Nov 19, 2011

I have this very simple code below that I use to delete a row if its marked as 'false' in column M. This works quite well, but I want to expand it. I use this in a workbook that can have name different sheet names in a month, and I want it to automatically go through all the sheets and do this...except for 2 sheets named addressess and sheet1. Is there something I can add to this macro that will loop through all the other sheet names (regardless of name) and execute this?

Sub DelRow()
With ActiveSheet
.AutoFilterMode = False
With Range("m1", Range("m" & Rows.Count).End(xlUp))
.AutoFilter 1, "false"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub

View 2 Replies View Related







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