Need help finishing a loop

copleyr

Active Member
Joined
Aug 24, 2009
Messages
381
Hello all:

The following code will go into multiple excel templates in a designated folder path, copy a row out of the "Defaults" tab, and paste it into a blank spreadsheet. Ive been getting errors when trying to change the code to do 3 things:

1) Instead of it going into just a Sheet called "Defaults", I need it to go in every Sheet in the Workbook.
2) Instead of it copying just one range in the sheet: "Range("A70:CO70").Copy", I need it to look for a unique word in one cell in column "A", Called "SBW". (There will only be one of these instances in column "A") Then I need it to copy the very next row Columns A through M.
3) Instead of it pasting into a new workbook, I'd like for it to paste into the tool that's currently open to use the macro tool.

Thanks in advance if you're able to help!



VBA Code:
Sub Copy_files()

Dim MyPathName As String

Dim MyFileName As String

Dim NumChars As Long

Dim X As Long

Dim SummarySheet As String


Workbooks.Add

SummarySheet = ActiveWorkbook.Name

MyPathName = "C:\Users\xxxxx\Desktop\All/" 'Change this to the folder and filetypes you want to return

MyFileName = Dir(MyPathName)

X = 0

Do While MyFileName <> ""

    X = X + 1


    Workbooks.Open MyPathName & MyFileName, False

    Application.DisplayAlerts = False

    Sheets("Defaults").Range("A70:CO70").Copy

    Workbooks(SummarySheet).Activate

    Range("A" & X & ":CO" & X).PasteSpecial xlPasteValuesAndNumberFormats

    Range("A" & X & ":CO" & X).PasteSpecial xlPasteFormats

    Workbooks(MyFileName).Close False


    MyFileName = Dir

Application.DisplayAlerts = True

Loop

End Sub

One note: The term "SBW" can be in multiple rows, hence the need for a "find" function in column "A"
 
Last edited by a moderator:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
What I meant to say in the one note is that "SBW" can be found in different rows in each excel template, hence the need for a "find" function in column "A"...
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

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