Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
End Sub
Sub R_and_A_Clean_New_Files()
'
' R_and_A_Clean_New_Files Macro
'
Dim i As Long
'Select Proper Work Sheet
Sheets("Files").Activate
'Change the row here accordingly (currently looking in row 3)
For i = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Left(Cells(8, i).Text, 1) = "Q" Then
Columns(i).Delete
End If
Next
'Change the column here according (currently looking at column D)
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Left(Range("G" & i).Text, 1) = "%" Then
Rows(i).Delete
End If
Next
'look in the used cells in a column and delete blank columns
For i = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Intersect(Columns(i), ActiveSheet.UsedRange) Is Nothing Then
Columns(i).Delete
ElseIf Application.WorksheetFunction.CountA(Intersect(Columns(i), ActiveSheet.UsedRange)) = 0 Then
Columns(i).Delete
End If
Next
'Rex Additions 12/18/2013
'Delete Blank Rows
'look in the used cells in a Row and delete blank rows
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Intersect(Rows(i), ActiveSheet.UsedRange) Is Nothing Then
Rows(i).Delete
ElseIf Application.WorksheetFunction.CountA(Intersect(Rows(i), ActiveSheet.UsedRange)) = 0 Then
Rows(i).Delete
End If
Next
'One more pass at deleting % of sales 12/18/2013
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Left(Range("E" & i).Text, 1) = "%" Then
Rows(i).Delete
End If
Next
'One more pass at deleting subtotals 12/18/2013
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Left(Range("E" & i).Text, 1) = "T" Then
Rows(i).Delete
End If
Next
'Delete Leftover Header Rows and Left Columns
Rows("1:5").Delete
'Columns("A:B").Delete
'Add Sales Header to two columns
Range("C2").FormulaR1C1 = "Sales"
Range("D2").FormulaR1C1 = "Sales"
'Add Casegoods to Correct Column
Range("B1").FormulaR1C1 = "Casegoods"
'Delete Column E (it's all blank)
Columns("E").Delete
'Delete Column A (it's all blank)
Columns("A").Delete
'Delete Blanks in Column C
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Left(Range("C" & i).Text, 1) = "" Then
Rows(i).Delete
End If
Next
'Delete FY Summary Columns (from mvidas)
For i = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Cells(1, i).Text Like "FY??" Then
Columns(i).Delete
End If
Next
'Delete Blank Month Columns (from mvidas)
For i = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Len(Cells(2, i).Text) = 0 Then
If Intersect(Columns(i), ActiveSheet.UsedRange) Is Nothing Then
Columns(i).Delete
ElseIf Application.Sum(Intersect(Columns(i), ActiveSheet.UsedRange, Rows("2:" & Rows.Count))) = 0 Then
Columns(i).Delete
End If
End If
Next
End Sub
You will probably want to put that in a normal code module, instead of on the worksheet module where it is. It shouldn't make a difference at runtime in this case, but it can in some instances. Unless it is a worksheet-level event or private function, its better to keep macros in normal modules.
The header column remover did not.
I realized that ONLY the 2nd row under those months is blank. (that's for sales, but they are future months)
However, they (accounting) do put zeroes in the future months for the other categories.
I am assuming that was the issue. I have included a picture to show you what it looks like.
thanks