Sub ProcessZFSC5(ByVal strName As String, Optional blnTimer As Boolean = True)
Dim start As Date
Dim strNewFile As String
strNewFile = Left(strName, Len(strName) - 4) & ".xlsx"
strNewName = Right(strNewFile, Len(strNewFile) - InStrRev(strNewFile, "\"))
' Dim headers As Variant
' headers = Array("", "Funds Center", "Fund", "Functional Area", "Funded Program", "Commitment Item", " AFP ", " Allotment ", " Commitment ", " Obligation ", " Expenses ", " Disbursement ", "Available Allot", " Avail AFP ")
start = Now
Application.ScreenUpdating = False
Workbooks.Add
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strNewFile, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, ConflictResolution:=xlLocalSessionChanges
Application.DisplayAlerts = True
Workbooks(strNewName).Close
Workbooks.Open Left(strName, Len(strName) - 4) & ".xlsx "
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strName, Destination:=Range("$A$1"))
.Name = "ZFSC5"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Do While Cells(1, 2) = ""
If Left(Trim(Cells(1, 1)), 19) = "Date of Selection: " Then
datRan = Cells(1, 1)
End If
Rows("1:1").Delete
Loop
Columns("A:A").Delete
Rows("2:3").Delete Shift:=xlUp
Range("A1").Select
Columns("B:G").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").FormulaR1C1 = "Funds Center"
Range("C1").FormulaR1C1 = "Fund"
Range("D1").FormulaR1C1 = "Functional Area"
Range("E1").FormulaR1C1 = "Funded Program"
Range("F1").FormulaR1C1 = "Commitment Item"
Range("G1").FormulaR1C1 = "Date Run"
Columns("B:G").NumberFormat = "General"
'Columns("G:G").NumberFormat = "@"
x = ActiveSheet.UsedRange.Rows.Count
Range("B2").FormulaR1C1 = "=IF(MID(RC[-1],4,1)=""*"",RC[-1],R[-1]C)"
Range("C2").FormulaR1C1 = "=IF(AND(MID(RC[-2],3,1)=""*"",MID(RC[-2],4,1)<>""*""),RC[-2],R[-1]C)"
Range("D2").FormulaR1C1 = "=IF(AND(MID(RC[-3],2,1)=""*"",MID(RC[-3],3,1)<>""*""),RC[-3],R[-1]C)"
Range("E2").FormulaR1C1 = "=IF(AND(LEFT(RC[-4],1)=""*"",MID(RC[-4],2,1)<>""*""),RC[-4],R[-1]C)"
Range("F2").FormulaR1C1 = "=IF(LEFT(RC[-5],1)<>""*"",RC[-5],R[-1]C)"
Range("G2").FormulaR1C1 = "=R[-1]C"
Range("B2:G2").AutoFill Destination:=Range("B2:G" & x)
Range("G2").FormulaR1C1 = Replace(Replace(datRan, " Date of Selection: ", ""), " Time of Selection: ", "")
Columns("B:G").Copy
Columns("B:G").PasteSpecial Paste:=xlPasteValues
Columns("G:G").NumberFormat = "m/d/yy h:mm:ss;@"
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$O$" & x).AutoFilter Field:=1, Criteria1:="=~**", Operator:=xlAnd
For i = x To 2 Step -1
If Rows(i & ":" & i).Hidden = False Then
Rows(i & ":" & i).Delete
End If
Next
Selection.AutoFilter
Range("A1").Select
Columns("A:A").Delete Shift:=xlToLeft
ActiveSheet.Range("$A$1:$N$" & x).AutoFilter Field:=7, Criteria1:="="
ActiveSheet.Range("$A$1:$N$" & x).AutoFilter Field:=8, Criteria1:="="
ActiveSheet.Range("$A$1:$N$" & x).AutoFilter Field:=9, Criteria1:="="
ActiveSheet.Range("$A$1:$N$" & x).AutoFilter Field:=10, Criteria1:="="
ActiveSheet.Range("$A$1:$N$" & x).AutoFilter Field:=11, Criteria1:="="
ActiveSheet.Range("$A$1:$N$" & x).AutoFilter Field:=12, Criteria1:="="
Rows("2:2").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter
Cells.Replace What:="~*", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows
For i = 1 To 5
For j = 2 To ActiveSheet.UsedRange.Rows.Count
Cells(j, i) = Trim(Cells(j, i))
If InStr(1, Cells(j, i), " ") Then Cells(j, i) = Left(Cells(j, i), InStr(1, Cells(j, i), " ") - 1)
Next
Next
Columns("A:E").NumberFormat = "@"
Cells.EntireColumn.AutoFit
ActiveWorkbook.Close True
If blnTimer Then MsgBox "Process took " & convertTimer(DateDiff("s", start, Now)) & " to run."
Application.ScreenUpdating = True
End Sub
No, I don't expect anyone to plow through that listing, nor make any changes to it, I am just trying to understand why those lines are not getting all of the data in the field. Since this is the first macro that hits the raw data, it has to happen here, because it is present before this macro, and gone afterwards...
Bookmarks