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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,330
Latest member
ThatGuyCap

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