Looping Through Items In A Folder

Apr 2, 2014

I am using this code:

VB:
Sub a()
Dim WB1 As Workbook, WB2 As Workbook, MyFile As String, Sep As String, WS As Worksheet
Dim R As Range, X As Integer, a As Range, b As Integer, rownum As Integer, WS1 As Worksheet
Dim R2 As Range, a2 As Range, row As Integer, sep2 As String, MyFile2 As String

[Code] ....

If I run this code without the miles of code i have between them, it loops through each workbook in the folder just fine.

However, I am getting a Runtime 5 error when it reaches Myfile = Dir() each time with my full code.

Here is the full code:

VB:
Private Sub CommandButton1_Click()
Dim WB1 As Workbook, WB2 As Workbook, MyFile As String, Sep As String, WS As Worksheet
Dim R As Range, X As Integer, a As Range, b As Integer, rownum As Integer, WS1 As Worksheet
Dim R2 As Range, a2 As Range, row As Integer, sep2 As String, MyFile2 As String
Sep = Application.PathSeparator

[Code] .....

Once again, I am getting the error message 3 lines from the very bottom ("MyFile = DIR()")

View 6 Replies


ADVERTISEMENT

Looping Through Files In A Folder

Jun 5, 2008

I have written a routine that prompts the user to select an Excel file (using Application. GetOpenFilename) then the routine pulls information from the selected file. I now want to have the user only select the folder and then have the routine loop through every file in the directory, pulling the information from each.

View 9 Replies View Related

Looping Through Folder And Copying And Pasting Into New Worksheet

May 1, 2007

I am looking to loop through a folder and open every workbook in the folder. For every workbook I would like to copy a range in a worksheet named "explain" and paste values into a separate file. All in all this separate file would be a consolidation of the information from the individual workbooks.

View 2 Replies View Related

Macro To Delete Items In A Folder

Aug 14, 2013

I have macro to copy data from one folder to another. However I would like a macro to delete the files in the source folder once copied

View 6 Replies View Related

Lookup Folder From Cell Text Then Save Excel File In This Folder

May 14, 2014

I have alot of project folders on my harddrive.

All in format: I:/12345-costumer-projectname/

The five digits are unique for each project.

I make calculations for these projects using an excel file. In this excel I also type the projectnumber (cell J2)

Now i would like to make a button. When pressed, it checks the projectnumber cell J2, looksup the corresponding folder and saves the excelfile in PDF format in this folder.

I have found macro to find files in folders, but none which do the above.

View 4 Replies View Related

Conditional Formatting IF Function To Identify Past Due Items In Red And Items Completed

Aug 13, 2014

I have a spreadsheet that lists a set of actions and the days they need to be completed.

The due dates are listed in column c and in column h I have a the user choosing "completed" from a drop down data validation.

I have a dashboard on a separate worksheet, showing if the item is complete and the due date.

Ideally I would like to display the dates on the dashboard in red if they are past due, and the box in column h was not marked complete.

I have been going through my books and trying to solve this, but I run into a different issues.

Even if for now If I can get the main worksheet to display the color conditional formatting that would work

View 2 Replies View Related

Excel 2003 :: Extract Variable Rows Of Cells From Files In A Folder To Existing File In Folder

Mar 15, 2013

I need a macro in a workbook to look at all the files in the same folder that have "*att*.xls" in the name and determine and copy from the range A15:W515 only the rows that have data in at least columns A, C and D. Each file will vary as to how many rows there will be and there are more than the files with "*att*.xls" in the folder. The data will be on the only worksheet in each file and the worksheet is named "G2WAttendee_xls" the data from all the files need to be copied to the file called "Consolidated webinar reports.xls" (I am using Excel 2003) and to a sheet called "Attendance Data" and added to the end of the last paste.

At the start of the macro the current file "Consolidated webinar report.xls" should be saved to a sub folder of the current directory and have the date saved added to the name. The sub folder is called "Completed reports". The data in the original file on worksheet "Attendance Data" should be deleted.

At the end of the process all the files that have had data copied from them should be moved to the sub folder "Attendance reports consolidated" (This could be done as each file is closed if that is easier).

I have headings in row 1 of the "Attendance Data" worksheet that match the headings in the various files in the folder (which will always be in row 14 of the individual "*att*.xls" files).

The folder with all the files and the "Consolidated webinar report.xls" file is at path "Z:P and S MEvaluationsWebinar series 2012-13TB".

View 9 Replies View Related

For All Workbooks In Folder - Copy Range To Different Workbook - Save To New Folder?

Apr 21, 2014

I have up to 50 workbooks in one folder with data in a specific range. I also have one workbook which includes additional data, including conditional formatting and dropdowns. I need to copy the desired range from the first workbook in the source folder to the second workbook, then save the latter to my destination folder, using the same name as the first. I need to repeat this process for all workbooks in the source folder.

View 2 Replies View Related

VBA Code To Find A Folder Name Within Parent Folder That Contains Defined Text

Jul 23, 2014

I have an Excel VBA Macro for creating/logging drawing numbers. Each drawing belongs to a job number. Each job number has a folder name containing the job number followed by a description (ie 999999 - bracket assembly) for storing drawing pdf's. The job number is only known as a 6 figure number in the drawing creation process BUT for the PDF saving process it is a string value...as my example above

I have to change my process by pre-creating the Job Number folder, then have the macro look for the appropriate folder by searching the parent folder for a sub folder containing the job number (always the first 6 figures).

I want to insert in my macro some code that searches...

The parent folder for a folder containing the job number. The macro value for the parent folder is P:engineeringdrawings (this never changes). the macro value for the job number is iOpenair (it's an entry that is entered as start the macro). Imagine the value for the job number is "999999"...so the search would be for "999999*.*" The code needs to search the parent folder, find the folder name that begins with a six digit number. Capture the complete name of the folder and store that name as a Dim value that I can call up elsewhere in my macro.

View 9 Replies View Related

Count Items In Column That Match Multiple Data Items?

Mar 27, 2014

I need to count the total number of times 4 different values appear in a column. This formula works for one value:

=COUNTIFS(Source!$C:$C,$B5,Source!$J:$J,$L$3,Source!$L:$L,$H$1)

Where H1 contains the word Assigned. I need to also find and add to count for matches in I1,J1 and K1 which contain New, Pending and Work in Progress respectively.

View 6 Replies View Related

Change (Browse For Folder) To Automatically Locate Sub Folder

Jul 23, 2012

I am creating a document for work that automatically generates hyperlinks to pdf files in a given sub folder. Currently I have a section of code that opens a window to choose the folder location.

Code:
'Prompt user to select a directory
Do
Problem = False
Set ShellApp = CreateObject("Shell.Application"). _
Browseforfolder(0, "Please choose a folder", 0, "c:\")

On Error Resume Next

[Code] ........

What I actually want is to not have the window open, but excel automatically choose the sub folder location.

The directory looks like this
Z:ClientProjectDRAWINGS-2 RECORD COPIESPDF

The xlsm file is stored in the DRAWINGS folder, and I need it to point to the PDF folder.

View 9 Replies View Related

Select Multiple Items In List And Then Print Those Items?

Dec 26, 2013

I am wanting to create a list where I can select multiple items within that list and then print only those selected items. I have created something similar thru data validation, but I can't get it to print.

In addition, I would like to be able to subdivide the list into multiple categories, then select items from these multiple categories and print them.

View 3 Replies View Related

Image Folder - Save 500 Images In Another Folder?

Jul 18, 2014

I have a list of items in an excel sheet... 500 of them... and there are images for them in an other folder... The problem is those images are in 1000's and I only need those 500 images.. Images are saved as "SKU.jpg eg NS2354.jpg and we have an SKU column in excel as well .. SKU and their images have same name...

Is there any solution to pick up only those 500 images from those thousands of images?

Is it possible to save those 500 images in an other folder?

View 2 Replies View Related

Macro To Locate Folder In A Folder And Save

Apr 13, 2009

looking for some code to save to a destination

destination address is
C:Documents and SettingsstDesktopOJF

now the problem is OJF has folders named 1 to 500

so if cell d5 = 487 it will need to look in the above desination and then open the folder and save it there.

View 10 Replies View Related

Excluding Selections: Added To The 20 Items And Not To The 3 Items

May 23, 2006

If i select 3 items from a list 20 items to be show on the cube this is fine and works however if i then add another item to the list i now have 21 items and for some reason it also adds itself to my 3 selected items to become 4 items. Is there anyway I can get it to be added to the 20 items and not to the 3 items..

View 4 Replies View Related

Loop Through A Folder And Save In Different Folder

Apr 26, 2014

I would like to create a code that will open all workbooks in folder "A" one at a time and then close the work book after another code is executed. So one workbook will open and while the workbook is open, I will call another code to format the active workbook and then the active workbook will be saved in folder "B" and closed and go to the next workbook in folder "A" to start all over. The folders are saved on the desktop.

View 5 Replies View Related

Locate Folder From Part Of Folder Name

May 23, 2007

if it's possible to use XlDialogOpen to open up a folder that you only have part of the name.

For example, say you have the following folder paths:

C:Main FolderSubfolder1Smith,Billy 2413
C:Main FolderSubfolder1Brown,Charlie Ray 2416
C:Main FolderSubfolder1Bunny,B 3619
C:Main FolderSubfolder1Fudd,E-G 1864

What I'm hoping to do is just look for the 4 digit number on the end finding that folder name and opening it up. The name conventions before the 4-digit serial number are quite random. Sometimes it includes their full first name, other times it's just an initial for the first name and other times there are other characters included in the name. The one thing that is constant is the 4 digit serial number on the end.

how I could get the Open dialog box to pop up and have the chosen folder number open?

View 6 Replies View Related

Creating A Unique List Of Items In Column A That Have A Corresponding Non-zero Value In Column B, I.e. Excluding All Items Where Sumif ColumnB Would Sum To 0

Jul 17, 2009

I know how to use array formulae to create a unique list, i.e.{=INDEX($G$1:$G$760,SMALL(IF(ROW($G$1:$G$760)=MATCH($G$1:$G$760,$G$1:$G$760,0),ROW($G$1:$G$760)),ROW()))}

however this is giving all the unique items from column G and I only want the unique items that have a non-zero value in column H as well. This would be the sumif of all instances that would have to be zero. I've tried to crack it and I've tried to search for solutions but so far no joy.

View 9 Replies View Related

VBA - Cut File From A Folder And Put Into Another Folder?

Oct 9, 2012

Is there a way I can from vba cut a file from a folder and put in to another folder? And also create a folder? If yes, how can I do this?

Is it better to use dir or scripting.filesystem object?and if there is an advantage to use one over the other.

View 2 Replies View Related

Looping For 01 To 10

Aug 8, 2014

I know how to loop for 1 to 10.

But is it possible to loop for 01 to 10?

Like:

[Code] ......

Because I am pulling data from external aplication, so the 0 is fix in a row/column.. I will need to get the row/column for the whole "01" and not only "1".

View 2 Replies View Related

For Next Looping

Aug 18, 2009

I am not sure what I am doing wrong with this expression. I know the code is a little messy, sorry.

View 2 Replies View Related

Looping Without Using VBA

Aug 8, 2009

Is it possible to write a cell formula (not a macro) to loop through a range of cells and test for a value? Something tells me that I need to use the "Offset" function.

View 9 Replies View Related

Looping Through The Last Row

Feb 14, 2010

How do I continue to loop through the last row and get the values to 3 differrent text boxes?

If I remember right, I think the command is Offset, 1 to go to the right one cell correct?

Sub CommandButton1_Click()
'("PowerAnalysis").cells(Row, 3).Value = textbox1.Value
'Worksheets("PowerData").Cells(Row, 3).Value = TextBox1.Value
Set WkSht = Worksheets("PowerData")
LastRow = WkSht.Range("A" & Rows.Count).End(xlUp).Row

WkSht.Cells(Row, 1).Value = TextBox1.Value

'LastRow = r
'r = ActiveCell
'Dim r As Long
'r = ActiveCell.Row
'UserForm3.Show

'WkSht.Cells(Row, 3).Value = TextBox1.Value
UserForm3.TextBox1.Value = r

End Sub

This code is wrong, but how can I get the first three records on the last row to display in three textboxes on UserForm3 titled TextBox1, TextBox2 and TextBox3.

Norie may be right, I may not have to even think about using repaint.

View 9 Replies View Related

VBA Looping

May 21, 2006

I have created a spreadsheet used for timber design. The spreadsheet calculates whether a specified size of timber column will support a specified load under certain conditions.

The various conditions include, load duration, service class, strength class and limit states.

Ok at the moment the user specifies the load and length of the column, then chooses a size of timber and sets the conditions mentioned above. Once this has been done the calculations i have put together on another sheet, work out whether the size of timber can support the specified load.

It is important to know that the answer for the final strength formula of determining the strength of the column should be equal to or less than 1. If this is the case then the column is ok, if the answer is larger than 1 then the column isnt safe.

Also at various points within the calculation certain checks are required to make sure certain design values satisfy certain criteria. If they dont then a new size of timber sould be tried.

What i would like to be able to do is use a loop so that the spreadsheet will use differing sizes of timber and calculate the values that satisfy the criteria and eventually find the size of timber required. The final answer of the strength calculation should be as close to 1 as possible but not over.

View 8 Replies View Related

Looping In Vba

Nov 5, 2006

My code is supposed to generate figures to plot the changes in a riverbed profile with time. At time zero, there is a main subroutine that goes through a number of Subroutines and iterations before ending. At time t, I have another main subroutine which is slightly different but would go through most of the subroutines of tine zero. I want the code to go through for time t=0, display the values and then go through the other loops as well, displaying the values for each loop. I thought I knew what I was doing, but the displayed results showed reasonable results for the first (time zero), but the others were just replicas of the same thing. Is there anyway I could use variables with vectors i.e patty(j,i), where i could run the loop for i, and then do Next j.

View 4 Replies View Related

VBA For Looping Through Rows?

Feb 8, 2013

I have the below code which converts a range to PDF and saves it on our network drive. I would like to change my code to a loop so I don't have to do so much typing. There are 68 rows between each range.

VB:
Sheets("CPS CSR Dashboards").Range("A2:K69").ExportAsFixedFormat xlTypePDF, "G:Call Center ReportingWeeklyAgent DashboardsTemp" & [ 'CPS CSR Dashboards'!M3] & ".pdf"
Sheets("CPS CSR Dashboards").Range("A70:K137").ExportAsFixedFormat xlTypePDF, "G:Call Center ReportingWeeklyAgent DashboardsTemp" & [ 'CPS CSR Dashboards'!M71] & ".pdf"

A2:K69 is the range for Agent 1 which will be saved as as a PDF M3 is the cell which contains Agent 1's name for which the file is to be named.

A70:K137 is the range for Agent 2 which will be saved as another PDF M71 is the cell which contains Agent 2's name.

View 1 Replies View Related

VBA - Looping Through Different Columns

Jul 6, 2013

I am trying to code something that will loop through a given set of columns. I know that if I say "For each C in R", that would mean, looping through each cell inside the Range "R", but what I want is something like this:

VB:
Dim rzRng As range, rzSmallRng As range
Set rzRng = Union(range("A:A"), range("C:C"), range("F:F"), range("AB:AB"), range("AS:AS"))

For Each rzSmallRng In rzRng
statement here...
Next

(I have a total of 30 columns that I need to put inside that Union function) . And then loop through the range as a whole set (not though each cell of that range).

I also tried the following code:

VB:
With Union(range("A:A"), range("C:C"), range("F:F"), range("AB:AB"), range("AS:AS"))
statement here....
End With

But it ended up executing the code in Range"A:A" only.

View 8 Replies View Related

Looping After Every 121 Cells

Mar 19, 2014

I have to manually drag my formula for 121 cells and then change the formula by next column and/or row number.

Currently the 2 formulas I have are:

=IF(AND($Z$4>="", $AA$4>=""),H$6,J2456)

=OFFSET(X$5,0,(ROWS($1:1)-1)*2)

After every 121 cells that I drag these formulas to, in the first formula I change from H$7 to H$7 then H$7 then H$7 and so on

In the second formula, I change from X$5 to X$6 then X$7 then X$8 and so on.And also change the ROWS from 1:121 back to 1:1

Is there a formula which I can drag and it automatically changes the column and cell reference in the 2 formulas?

View 6 Replies View Related

Looping Through ListObject?

Apr 11, 2014

I am looking to create a loop in a ListObject object that does calculations depending on the value of the current certain row in a column. This is the code I have so far:

[Code]....

I am having trouble with the loop; as you can see, the nested for loop will go through all the 'weight' in the column before going to the next 'grade'. I just want the loop to reference the same 'weight' that the 'grade' is on and move on. But I am not sure how to reference each 'weight' as I progress through each 'grade' in parallel.

I am aware that I can do this with regular cell references:

[Code] ......

but I am more interested in learning on how to work with the ListObject class.

View 2 Replies View Related

Looping Code

Apr 28, 2007

I am using the following code in a project and would like some help to loop it until either TRUE or #N/A is found in the active cell.

View 9 Replies View Related







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