I'm probably trying something too intense for a newbie such as myself, but I am attempting to construct/convert a program that will load all the text files from a specific folder and make them all worksheets in the same workbook, name them after their original titles, format the columns, and then make some graphs. So far I've been using other programs I've found online and attempting to glue the bits and pieces together, but can't get the whole thing to work together.
My program can download and rename without a problem, but can only do the initial formatting (column widths and hiding columns) for the first sheet. It also pops up an error whenever I try to have it insert a row between differing values in column U (which I am trying to do so I can graph more easily).
The final goal is to have a workbook full of spreadsheets that show the data and graphs of the BOD and Flow results. Am I going about this the wrong way? Any tips on what to change to finish the formatting and to have it carry across all the sheets?
I've included both the program as it stands now and a sample of the data (it compressed the blank cells, but the colum containing Flow Rate and BOD5 is U). Thanks!
Sub GetTextFiles()
Dim lngCounter As Long, wbText As Workbook
On Error GoTo ErrHandler
Dim FolderName As String
Dim FolderLen As Integer
Dim FileName As String
Dim FileLen As Integer
Dim TabName As String
Dim Parameter As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.FileType = msoFileTypeAllFiles
FolderName = InputBox("Copy the path from the Addressbar" & vbNewLine & "and paste it in here")
.LookIn = FolderName
.Execute
For lngCounter = 1 To .FoundFiles.Count
If Right(.FoundFiles(lngCounter), 4) = ".txt" Then
Workbooks.OpenText .FoundFiles(lngCounter)
ActiveSheet.UsedRange.Copy
ActiveWorkbook.Close False
ThisWorkbook.Sheets.Add
ActiveSheet.Paste
FolderLen = Len(FolderName)
FileLen = Len(.FoundFiles(lngCounter))
FileName = Right(.FoundFiles(lngCounter), FileLen - FolderLen - 1)
TabName = Left(FileName, FileLen - FolderLen - 1 - 4)
ActiveSheet.Name = TabName
ActiveSheet.Columns("A:A, E:H, J:T, W:Y").Hidden = True
Columns("B").ColumnWidth = 35
Columns("C").ColumnWidth = 14
Columns("D").ColumnWidth = 9
Columns("I").ColumnWidth = 8
Columns("U").ColumnWidth = 30
Columns("V").ColumnWidth = 14
a = 1
Do Until a = ActiveSheet.Cells(Rows.Count, 21).End(xlUp).Row
If ActiveSheet.Cells(a, 21).Value = ActiveSheet.Cells(a - 1, 21).Value Then
Else: ActiveSheet.Rows(a + 1).Insert
End If
a = a + 1
Loop
End If
Next lngCounter
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
Application.ScreenUpdating = True
MsgBox Err.Description, vbExclamation, "Ooops, an error occurred"
End Sub
23622141 NON-CONTACT COOLING WATER 0.22 3 12 300658 1 Y 211 07/13/2012 17:07 W11559 N Flow Rate MGD 50584 N
23622142 NON-CONTACT COOLING WATER 0 3 13 300658 1 Y 211 07/13/2012 17:07 W11559 N Flow Rate MGD 50584 N
22946012 NON-CONTACT COOLING WATER 67 15 50 293976 1 Y 487 02/08/2012 17:04 W11559 N Temperature deg F 50584 N
23080924 NON-CONTACT COOLING WATER 71 15 30 293268 1 Y 487 03/09/2012 16:46 W11559 N Temperature deg F 50584 N
23209609 NON-CONTACT COOLING WATER 71 15 13 293586 1 Y 487 04/11/2012 17:01 W11559 N Temperature deg F 50584 N
23325890 NON-CONTACT COOLING WATER 70 15 31 301032 1 Y 487 05/04/2012 17:02 W11559 N Temperature deg F 50584 N
23460218 NON-CONTACT COOLING WATER 72 15 32 301017 1 Y 487 06/08/2012 17:00 W11559 N Temperature deg F 50584 N
23622143 NON-CONTACT COOLING WATER 69 15 14 300658 1 Y 487 07/13/2012 17:07 W11559 N Temperature deg F 50584 N
22946046 NON-CONTACT COOLING WATER 2 19 18 293976 2 Y 66 02/08/2012 17:04 W11559 < N BOD5, Total mg/L 50585 N
23080956 NON-CONTACT COOLING WATER 2 19 62 293268 2 Y 66 03/09/2012 16:46 W11559 < N BOD5, Total mg/L 50585 N
23209643 NON-CONTACT COOLING WATER 2 19 47 293586 2 Y 66 04/11/2012 17:01 W11559 < N BOD5, Total mg/L 50585 N
23325923 NON-CONTACT COOLING WATER 2 19 64 301032 2 Y 66 05/04/2012 17:02 W11559 < N BOD5, Total mg/L 50585 N
23460252 NON-CONTACT COOLING WATER 2 19 66 301017 2 Y 66 06/08/2012 17:00 W11559 < N BOD5, Total mg/L 50585 N
23622176 NON-CONTACT COOLING WATER 2 19 47 300658 2 Y 66 07/13/2012 17:07 W11559 < N BOD5, Total mg/L 50585 N
22946014 NON-CONTACT COOLING WATER 0.326 3 52 293976 2 Y 211 02/08/2012 17:04 W11559 N Flow Rate MGD 50585 N
22946015 NON-CONTACT COOLING WATER 0.326 3 53 293976 2 Y 211 02/08/2012 17:04 W11559 N Flow Rate MGD 50585 N
22946016 NON-CONTACT COOLING WATER 0.326 3 54 293976 2 Y 211 02/08/2012 17:04 W11559 N Flow Rate MGD 50585 N
Bookmarks