Macro loops

sudak091

New Member
Joined
Aug 15, 2011
Messages
4
[FONT=Times New Roman, serif]Hello Excel Experts

I am a SAS user and not very familiar with VB. But I have to perform some tasks on VB as I think it will be the fastest way of doing it instead of using a DDE (dynamic data exchange process in SAS).
The Steps I need to perform such as copy paste, replace aren’t too hard to figure out. But here is the kicker I need this code to run through a loop. There are about 1000 or so workbooks in a folder, all named in a certain naming convention. I need to the code to [FONT=Times New Roman, serif]copy a sheet from one Workbook put it into a new workbook and replace cell values with the file name that the loop finds so that the cell will reference the files found in the loop and then save it under another naming convention. I know this is very complicated, so any help is greatly appreciated...[/FONT]

Here is exactly what I need to get done

I have a Workbook called “GenericImportSheet” and a sheet within that is called “ImportSheet”. This sheet has generic cell references, e.g. [FONT=Arial, sans-serif]XXX!$D$10[/FONT]

I basically need the code to replace XXX with the file path and file name "='G:\AE\TEST\[Filename the LOOP finds in the folder location.XLS]Sheetname of that file'"

Step 1: Start the loop. Go into location 'G:\AE\TEST\ - there are going to be about 1000 files in here.

Step 2: I need to create a new Workbook and put the “ImportSheet” from the [FONT=Times New Roman, serif]“GenericImportSheet” workbook [/FONT]in to it and delete all the other sheets (i.e. Sheets 1,2,3)

Step 2: I need to rename the Worksheet as “Import_SHEETNAME of each of files the loop finds” (i.e. Import_ AGR Section I)

Step 3: I need to replace XXX in the new workbook with ='G:\AE\TEST\[File name of the file the LOOP finds.XLS] and Sheetname' – this would make the reference valid (e.g. ='G:\AE\TEST\[AGR Section I.XLS]AGR Section I'

Step 4: Save this new workbook in a new location with the same name as the sheet (i.e. Import_ AGR Section I)

Step 5: close this workbook and go to the next file – repeat steps.

I know this is super complicated. But I am going to have about 1000 or maybe more workbooks to deal with and I don’t want to do this manually. I know there should be some way to do this. Any help will be great. If only part of this loop can be performed that’s ok too. That will save me a lot of time and effort.

thank you in advance to one and all

[/FONT]
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,575
Messages
6,179,637
Members
452,934
Latest member
Jdsonne31

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top