Capture header rows from all Excel worksheets in a directory to a separate master file

marts2003

New Member
Joined
Oct 12, 2017
Messages
11
Hi there,

I already have VBA code that will recursively trawl through a directory. I am currently using this to identify if any columns in any of the worksheets in any of the Excel workbooks within that directory contain email addresses and, if so, those columns are then deleted.


Here's the find and delete loop:


Code:
Dim wsCurrent1 As Worksheet
Dim B As Range
For Each wsCurrent1 In ActiveWorkbook.Worksheets
    Do
    Set B = wsCurrent1.Columns.Find(What:="*@*", LookIn:=xlValues, lookat:=xlPart)
    If B Is Nothing Then Exit Do
    B.EntireColumn.Delete
Loop
Next wsCurrent1




What I'd really like help with is to see if it's possible to modify this loop, so that instead of finding columns to delete, it copies the header row (of every worksheet in every workbook within the directory) and pastes them into a separate master file. I have seen code that more-or-less achieves this objective elsewhere - but not within the context of a RecursiveDir approach.


Any suggestions gratefully received (even if it's just to say it can't be done this way!).


Thank you,
Martin.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,223,714
Messages
6,174,052
Members
452,542
Latest member
Bricklin

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