Pull data from many, poorly named files!

Stu Dapples

Active Member
Joined
Jan 12, 2009
Messages
252
I am honestly starting to think the people I work with are doing things like this to prove I can't do what they are asking! Fortunately for me, you guys have so far helped me to prove that these things are possible even for mere mortals such as myself! Anyway, enough "smoke blowing" ! :)

I have been asked to get the data out of 2 specific columns from a data sheet which is filled in on each shift and saved. The nomenclature for saving is poor to say the least....
Basically, I have about 350 workbooks with names such as 150kg_NIGHT242, 150kg_MORNING173
where 150kg is the machine, NIGHT/ MORNING is the shift and 242 is 24th of Feb, 173 is 17th March etc.
Is it possible to write some script and point it at all files in directory, regardless of filename? Maybe some sort of wildcard? eg, if filename = 150kg* then run the script?
I toyed with the idea of a user form to get someone to select which file to run the code on, it is do-able but still going to be a long task to get all the data out of 350 plus files....
Any advice, even a direction to start going, would be very much appreciated (and prove to the proliteriate that Excel is unstaoppable!!)
Thanks in advance,
Stu
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi Stu

Dir is what you need:

Code:
Const PTH As String = "C:\SomeFolder\SomeOtherFolder\"
 
Dim wb As Workbook
 
Dim strFile As String
 
strFile = Dir(PTH & "150kg*")
 
If Len(strFile)>0 Then
   Do
       Set wb = Workbooks.Open(PTH & strFile)
       ' whatever processing code you have
       wb.Close
       strFile = Dir
    Loop Until Len(strFile)=0
End If
 
Upvote 0
Hi Stu

Dir is what you need:

Code:
Const PTH As String = "C:\SomeFolder\SomeOtherFolder\"
 
Dim wb As Workbook
 
Dim strFile As String
 
strFile = Dir(PTH & "150kg*")
 
If Len(strFile)>0 Then
   Do
       Set wb = Workbooks.Open(PTH & strFile)
       ' whatever processing code you have
       wb.Close
       strFile = Dir
    Loop Until Len(strFile)=0
End If

Hi there, looks great and I can understand what it is supposed to do, I ran some basic code (select a couple of cells, copy them and bring them back to new book) but when I run the code, it errors saying Comile error, constant expression required....
I put this into a module and named it as a public sub, not sure if that will make any difference?
Thanks for you help,
Stu
 
Upvote 0
Hi there, just a quick note to say THANKS!! I had a tinker with the code and (as usual) it was my error, helps if you dont point the paste to the same cell each time....

Hey ho, every day is a school day!
Many thanks,

Stu
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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