Nested Loop Not Working; Pulls Data From Multiple Files Into One Table

Aug 8, 2006

I've got this code that pulls data from multiple files into one table. the file name is in the top row, and each file's title, and two different sums display below that. Then it is supposed to loop through and display each task and the start and end date for that task within each file. After that the first loop brings it to the next column and file. The primary loop works fine, but the inner loop only seems to run once, as I get only the first result for each file. All I can figure is that maybe my row numbers aren't resetting like they're supposed to, or I'm completely overlooking something, which is likely, as VBA is by no means my forte.

Sub Worksheet_Calculate()
Dim sBook As String
On Error Resume Next
Application.EnableEvents = False
Col = 8
' Sets start column
Do
sBook = Cells(2, Col)
' References file name
TaskRow = 6 ........................

View 5 Replies


ADVERTISEMENT

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

Running Query To Access: Pulls Data From 2 Columns In A Table And Pastes It To The Spreadsheet

Jul 10, 2009

I have an Excel spreadsheet with a query to an Access table. The query pulls data from 2 columns in a table and pastes it to the spreadsheet. I am trying to update the VBA a little on one sheet and now I get the attached error whenever the code tries to run in Excel. Here is the code with the offending portion separated at the top.

View 2 Replies View Related

Nested Loop To Concatenate 2 Columns Of Data

Oct 27, 2009

I think I just need a basic Nested For Loop code. I have a list of in column A, from A1:A537 and another list in column B, for B1:B50. I want to add a column that concatenates, each item in Column A to B1 (so 537 rows), then again each item in Column A to B2, another 537 rows, etc.. this loop is repeated 50 times, one for each name in column B.

View 3 Replies View Related

Loop Through Multiple Files To Create List Of Tab Names

Jul 26, 2013

I have a folder with 20 Excel files. I'm trying to create a master list of all the tab names. I can see all of the files opening, but it only copies some of the names.

VB:

Sub GetTabNames()
Dim wkBook1, wkBook2 As Workbook
Dim stFilePath1 As String
Dim FileList(1 To 18) As String
Dim iLoopSheet, iLoopProg As Integer
Application.ScreenUpdating = False

[Code] .....

View 2 Replies View Related

VBA - Attach Multiple Files To Email Using Folder Path Loop?

Feb 7, 2014

I have two pieces of code that each work, but I am struggling to combine the two.

I started with Ron de Bruin's code to attach multiple files to an email and then found more code that will loop through a folder to attach multiple files to an email.

Essentially, I would like the structure of Ron de Bruin's code, with the ability to have folder paths in the cell range, rather than file names.

Here is the code that works to loop through a folder, but it only works when I have the paths listed in one column, not in a range (e.g. columns C-Z)

Code:
Sub Send_Indv_Files()
Dim OutApp As Object
Dim OutMail As Object

[Code].....

View 4 Replies View Related

Pulls And Sums From A Reference Table For Highlighted Yellow Area

May 28, 2012

I need a formula for the highlighted yellow area that pulls and sums from a reference table. Not a traditional Vlookup because the reference within the report can appear in multiple columns within multiple rows.

ReportABCDEF1AccountJanFebMarApr2Overtime(L7)Overtime300 300 300 300 3
Salaries(L8)Salaries1,170 1,170 1,170 1,170
Expected ResultsReference PageABCDEF1
Account 1Account 2JanFebMarApr2
Additional PayOvertime(L7)1251251251253
Additional PayOvertime(L7)1751751751754
Salaries(L8)Ex Staff2252252252255Salaries(L8)
Ex Staff3253253253256Salaries(L8)Ex Staff4104104104107Salaries(L8)
NE Saff1101101101108Salaries(L8)NE Saff100100100100

View 2 Replies View Related

Nested Loop. Inner Loop Not Running

Nov 30, 2006

i have a problem with a nested loop:

it seems like the first instance of the code is running the way i want it to run, but when it starts with the second instance, it does the first search and copy, but it seems like the nested loop is being ignored.

am i doing something wrong?

dan
==========================================================
Thanks to Aaron Blood for the find_range function. i also poached the lastrow function from somewhere on ozgrid, but I cant remember the name of the poster.
==========================================================

Sub new2()

Dim Org_Area As Variant
Dim Item As Variant
Dim Copy_To1 As Variant
Dim Cell_Ref As Variant

r = 1 ..................

View 9 Replies View Related

Loop Through Files, Match & Return Data

Oct 26, 2006

I found a use for the “Looping Through Workbooks” code (recommended by Dave in my last thread - thanks Dave).

I have a number of small files in "C:Files" that I’d like to loop through and find a match with data from a Master (in another folder) workbook as follows.

1. Match columns ”C” of each of the files with column ”H” of the Master.
2. For each matching cells, insert data from column “I” of the Master (“ Date” field) to into col “D” for each row of the individual files (about 300 rows)
3. Save & Close the workbook and loop to the next one in that folder

All that's needed here is code to search, match & paste, to insert into Dave's "Looping Through Files" code.

View 9 Replies View Related

VLookup Multiple Values In Table - Not Working

Jun 13, 2013

I am trying to use a =vlookup(and( type formula. Excel accepted my syntax, but the formula is not working. Here are the details:

=VLOOKUP(AND(E2,O2),'[SOURCE DATA FOR PROFILES.xlsx]Sheet1'!$B:$G,6,FALSE)

The values from cell E2 and O2 are both present on a row in the SOURCE DATA spreadsheet, and column 6 is the last column in my table (both values appear before column 6, but not next to each other).

The formula returns #N/A. Under those circumstances, shouldn't it return the value of column 6 on the row where those two values are present together?

Do the columns containing the values have to be next to each other in the table for this to work? Does the data type matter (one is a number, the other a street address)? The value to be returned is a number.

View 5 Replies View Related

Convert Horizontal Data To Vertical - Loop Through Files In Folder

Apr 9, 2014

I have a set of workbooks-all located in the same folder-in which data are shown "horizontally"

i.e. file 1 - sheet1 looks more or less like this:

1 2 3
4 5 6

same with the other files.

what I am trying to achieve is that in another woorkbook, all the data are copied in one vertical vector

i.e

1
2
3
4
5
6 from file 1 and then
1
2
3
4
5
6 from file 2

I can seem to be able to resize the array to the correct size but the only values copied are for the last file. in the example that I have above, the result would look something like:

<empty>
<empty>
<empty>
<empty>
<empty>
<empty>
1
2
3
4
5
6

This is the code I have so far:

Sub Consolidate()

Dim a As Workbook
Dim b As Workbook
Dim x, y(), i&, j&, k&
Dim myPath As String
Dim filename As String
Dim wb As Workbook

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

View 11 Replies View Related

Nested IF Formula Not Working?

Nov 18, 2012

where the issue with the following formula is?

=IF(AND($E$2="N",$AA$550),"BT1",IF(AND(Z5="F",Y5>=0),"CLEAR",IF($AA$5

View 2 Replies View Related

Open Set Of Files To Fetch Data Starting From A Master File Where The Links Are Given Using A Loop

Aug 29, 2006

I am trying to open set of excel files to fetch data starting from a master excel file where the links are given using a loop. Some of files given as links are either absent or the link is wrong.

* What is the syntax to find if the link is correct/present

* What is the syntax to find if the file is present in specified location

* What is the syntax to find if the file is password protected to open

* I use error handler to resume the next statement if OPEN statement fails.It works fine inside the loop only for first two files.

For example if the third link is errorneous the error handler fails and RUN TIME ERROR occurs.

View 5 Replies View Related

Nested For Each Next Loop

Feb 17, 2007

I think its something simple I'm missing here. I have a range of stock prices (Range("E3,E4,E5,E6")) what I'm trying to do is use for each next loop to calculate the number of shares that I could trade. and place those shares in a range of cells adjacent to its corresponding price (Range("G3,G4,G5,G6")). I think the problem is in my loop statements but I can't seem to find it . Could someone kindly show me the error in my ways.

Code: ...

View 9 Replies View Related

Creating Nested For Loop

Feb 4, 2013

I'm trying to finish writing the last portion of a macro created to automate my data analysis project for my research but I'm having trouble writing the last For Loop of the code. I have a target cell B25 which states a given temperature of my reaction. Once a value is entered in B25, 5 activity coefficients are calculated and displayed in cells B31,35,39,43, and 47 which I would then like to copy and paste in cells J31-J35.

However, I'd like to calculate the activity coefficients for a range of temperatures which are listed in cells J30-W30. Thus, I need to create a For loop which copies the value from J30 into B25, copies the values from B31,35,39,43, and 47 to J31-J35 and then moves to the next column replaces the value of B25 with K30 and repeats the same process until all the columns are filled.

View 2 Replies View Related

Nested For Next Loop With VLookup

May 25, 2014

I have 2 sheets in the same workbook -- Entry and Setup. Setup sheet contains details about each class including how many arenas are going to be used for the event. The entries need to be divided up amongst the arenas. We are dealing with around 500 entries.

Setup Sheet
Class Number
Number of Arenas Used
Class 1

[Code].....

View 3 Replies View Related

Nested Control Loop

May 21, 2009

I'd like to know how I can loop through a series of frames and loop through each of the option buttons in each frame and write the value of the selected option back to a worksheet.

Here's an example of how I'm doing it now:

For Each ctl In fraWorkMode.Controls
If ctl.Value = True Then
ws.Range("A1").Value = ctl.Caption
Exit For
End If
Next ctl
For Each ctl In fraTransport.Controls
If ctl.Value = True Then
ws.Range("B1").Value = ctl.Caption
Exit For
End If
Next ctl
For Each ctl In fraTravelTime.Controls
If ctl.Value = True Then
ws.Range("C1").Value = ctl.Caption
Exit For
End If
Next ctl

I'm also thinking that OFFSET is maybe a better option than specifying each cell for the collected data.

These frames are on Userforms for a survey and some of the frames contain up to twelve other frames so a nested loop approach appears to be more efficient.

View 9 Replies View Related

Speed Up Nested Loop

Jul 20, 2006

how to speed up the following loop? It takes about 40 seconds.

Application. ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim x As Integer
Dim y As Integer
Dim Snominaloc As Double
Dim Scs As Double
Dim Sirating As String
Dim Mnominaloc As Range
Dim Mcs As Range
Dim Mirating As Range
Dim Mcbrating As Range

Set Mnominaloc = Worksheets("Parameters").Range("b10")
Set Mcs = Worksheets("Parameters").Range("b22")
Set Mirating = Worksheets("Parameters").Range("b12")
Set Mcbrating = Worksheets("EL").Range("b33")......................

View 2 Replies View Related

IFERROR Formula Not Working With Nested IF Statements And ROUND

Jan 11, 2010

I am trying to use the following formula in Microsoft Excel 2007-

ROUND(IF(DataInput!$D$5 = "Black",0.81*E4*O4,(IF(DataInput!$D$5 = "Red",J4*0.025*E4*O4,(IF(DataInput!$D$5="Green",(57.00+IF(J4>25,(J4-50)*33.59,0))*O4))))),2

I want to use an IFERROR statement. If the results do not equal Black, Red or Green, I want the data to error so I can have the word FIX showing.

View 2 Replies View Related

Nested Countif Not Working: Track Metrics For A QC Department

Nov 26, 2008

I am trying to track metrics for a QC dept. Right now my sheet has 35 lines of data and a header row, for 36 lines total. This is my funtion that isn't quite right:

View 2 Replies View Related

Nested Loop Hangs Excel?

Jul 4, 2014

I have a problem with a nested loop in my macro as Excel hangs every time i run my script. I suspect it is because my sheets have too many elements.

I am doing a software localization, and I need to translate records in column A (english) to column X (slovenian) in the same row. With each new version of the software, the number of rows changes.

I already manually did one translation (44000 rows), and now i need to do a new version translation, so I want to use my old translation (because many if not most of the elements are the same) and insert values into the new excel file.

In the new file in sheet1 I have a full column A with english words and an empty C column with slovenian words that I need to fill.

Into sheet2 I copied the old english in column A and slovenian translation in column B.

On sheet 3 i created a button that when clicked, goes though each row in sheet1.columnA, compares it to sheet2.colimnA, and if there is a match, copies the value from sheet2.columnB into sheet1.columnC. So, this should fill most of the translations I need to do, and the rest I will do manually

I am quite new to VBA so this is what I came up with:

[Code]....

The number of rows is around 44000 in each sheet. How I could optimize or even completely avoid the nested loop, because each time i click the button I need to wait for almost an hour and then Excel hangs.

View 8 Replies View Related

Nested Loops. Start & End Loop

Dec 5, 2006

is there any body kind enough to look into this code and tell me from where the loop body starts and ends and which is the loop variable and how it is being incremented or decremented. i know it is a stupid question but i admit here that i learn and manage to update my sheets only because of this forum help, as i have absolutly no idea of VBA when i started some couple of months back but know i can do little bits.
thanx again for all the help i got so far and hope to get some solution this time as well

Sub LowRisk_Chart()
Clearout
Voffset = 0
Vcounter1 = 2
Vline = Sheets("ChartWork"). Cells(Vcounter1, 1)
Vblocks = Sheets("ChartWork").Cells(Vcounter1, 4)
Vstdman = Sheets("ChartWork").Cells(Vcounter1, 5)
Vlength = Vblocks

View 3 Replies View Related

Nested Loop To Divide Adjacent Row By Column

Jan 18, 2010

I am trying to loop through Column Q2:Q2000, and divide the adjacent Row R2:HS2 by the value in the corresponding Q column.

ie. cells R2: HS2 should all be divided by Q2
cells R3:HS3 should all be divided by Q3
etc until R2000:HS2000 are divided by Q2000

I presume that i would require an initial loop to scroll through the column and a seperate loop to scroll through the row values, but i cannot get my head around how this is done.

View 14 Replies View Related

Nested For Next Loop W/ Multipule Arrays Sequence

Oct 30, 2009

I'm having some problems understanding how to change the sequence in loop structures..

This isn't the entire code, but maybe it will get the point across.

Currently the loop is giving me the following sequence..

"CL" "WTI OI" "HO OI" "RB OI"
"HO" "WTI OI" "HO OI" "RB OI"
"RB" "WTI OI" "HO OI" "RB OI"

What I want to get is:

"CL" "WTI OI"
"HO" "HO OI"
"RB' "RB OI"

Is there a way to the loop to go to: x y x y x y
Instead of: x y y y x y y y

Dim ContractCode As Variant
Dim ContractTab As Variant

ContractCode = Array("CL", "HO", "RB")
ContractTab = Array("WTI OI", "HO OI", "RB OI")

For Each x In ContractCode
For Each y In ContractTab
Debug.Print y
Debug.Print x

Selection.AutoFilter
Selection.AutoFilter Field:=3, Criteria1:=x
Cells.Select
Selection.Copy

Sheets(y).Select
Range("A3").Select
ActiveSheet.Paste

Next
Next

View 9 Replies View Related

VBScript That Pulls SNMP Data From Some Devices

Nov 21, 2008

I have a VBScript that pulls SNMP data from some devices. It uses two external EXE's called "SNMPGET.EXE" & "SNMPWALK.EXE". When the script runs, it pulls specific information from our SNMP devices (in this case, I am pulling temperature values from Netboz Devices). The script looks like this :

View 2 Replies View Related

Vlookup That Pulls Data From Another Work Sheet

Dec 1, 2006

i have created a Vlookup that pulls data from another work sheet, it all works fine apart from this one thing....

On a work sheet i have a lot of hyperlinks that work fine, but as soon as they get pulled over using a Vlookup, the name of the hyperlink comes accross for example "link 1" but you can not click on it to take you to the link like you can on the original one.

View 14 Replies View Related

Loop Through Data In Second Column Of Pivot Table

Sep 27, 2012

I have a pivot table with two columns: Code and Quantity. I want to loop through the Quantity column and hide all values = 0. I can do this easily by incorporating this into my code:

Code:
pt.PivotFields("Code").PivotFilters.Add _
Type:=xlValueDoesNotEqual, DataField:=pt.PivotFields("Sum of Quantity"), Value1:=0

However, I have a "(blank)" code in all pivot tables. I do this because occasionally there is no data to organize in a pivot table. Having a "(blank)" option will allow my code to work even when there's no data. Therefore, I want to keep blank visible at all times. The above code hides "(blank)", however.

The below code is what I've tried with no success.

Code:
Set pf = pt.PivotFields("code")
For Each pi In pf.PivotItems
If pi.PivotFields("Sum of Quantity").Value = 0 Then

[Code] ........

View 4 Replies View Related

Nested Next Loop: Evaluate The If Statement Below Over A Range Of Cells

Aug 22, 2008

I think the problem is the order in which I have the "next" loops. I would like to evaluate the if statement below over a range of cells

Sub Analysis()

Dim i As Integer
Dim x As Integer
Dim y As Integer
Dim k As Integer
Dim TheLast As Integer

TheLast = Sheets("Name").Range("c" & Rows.Count).End(xlUp).Row

For i = -7 To -26 Step -1
For x = 24 To 43
For y = 14 To 43
For k = 16 To TheLast.................

View 9 Replies View Related

Master Spreadsheet Pulls Variable File Name Data

Jan 22, 2014

I'm creating a master spreadsheet and I want it to pull live data from other spreadsheets depending on a variable.

I've a cell that has a variable date. I've files saved that have this variable attached to it in the name format: 'filename variable'.

I want to pull data, hopefully live, from workbooks based on this variable.

For example, I have files: generic 01212014, generic 01222014, generic 01232014.

The date is stored in the master workbook say in A1 that I can manipulate by entering a different date to pull data from a different workbook.

='[generic 01212014.xlsm]Database'!$L$3
='[generic 01222014.xlsm]Database'!$L$3
='[generic 01232014.xlsm]Database'!$L$3

There has to be away to make the bolded portions of the file name variable, right?

View 2 Replies View Related

Vlookup: Pulls The Wrong Data Until A Correct One Occurs

Jul 13, 2009

I am having problems with the function vlookup. I attached an excel file of my problem. It seems to pull the correct lookup, then it pulls the wrong data until a correct one occurs. My excel attachment should make more since of my problem. It will also pull data that is invalid. For example, the name "S5" is not a in my original data so it should not be able to find that?? Sorry, this is hard to explain - let me know if the file is not clear enough.

View 3 Replies View Related







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