I have a macro that is called "Delete Junk" which strips out unnecessary columns and rows from a workbook I download 2-3 times a week. The code is listed below.
Now I need this macro to also add columns and perform calcs.
For instance, after the steps below are done, I'm left with columns A-V. I now want to add a few more columns starting at W.
for W I'd like to do this:
=V2*0.1112 in W2
fill down to the end of the worksheet rows.
For AA I'd like to do this in AA2
=IF(Y2>Z2,Z2,Y2)
and then fill down to the end of the worksheet rows.
And so on. I have about 15 other columns with formulas I'd like to add, and one of them being the =Hyperlink formula.
Can this be done?
And is my original macro clean and doing it the right way?
Thanks,
Jeff
Now I need this macro to also add columns and perform calcs.
For instance, after the steps below are done, I'm left with columns A-V. I now want to add a few more columns starting at W.
for W I'd like to do this:
=V2*0.1112 in W2
fill down to the end of the worksheet rows.
For AA I'd like to do this in AA2
=IF(Y2>Z2,Z2,Y2)
and then fill down to the end of the worksheet rows.
And so on. I have about 15 other columns with formulas I'd like to add, and one of them being the =Hyperlink formula.
Can this be done?
And is my original macro clean and doing it the right way?
Thanks,
Jeff
Sub DeleteJunk()
Dim FilterRange As Range
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
'Delete rows 1 thru 13
Range("A1:A11").EntireRow.Delete
'Delete rows where column(a)="District:"
Set FilterRange = Range("A2:AC" & FinalRow)
FilterRange.AutoFilter Field:=1, Criteria1:="District:"
FilterRange.SpecialCells(xlCellTypeVisible).EntireRow.Delete
'Delete blue rows
For Each c In Range("A3:AC" & FinalRow)
If c.Interior.ColorIndex = 35 Then c.EntireRow.Delete
Next
'Delete all rows that contain no data
Dim i As Long
Dim lLastRow As Long
lLastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Application.ScreenUpdating = False
For i = lLastRow To 1 Step -1
If WorksheetFunction.CountA(ActiveSheet.Rows(i)) = 0 Then
ActiveSheet.Rows(i).EntireRow.Delete
End If
Next i
Application.ScreenUpdating = True
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Vendor in Row 1
If Cells(1, delCol) = "Vendor" Then _
Cells(1, delCol).EntireColumn.Delete
Next
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Name Me in Row 1
If Cells(1, delCol) = "Seq No" Then _
Cells(1, delCol).EntireColumn.Delete
Next
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Name Me in Row 1
If Cells(1, delCol) = "Lifetime Mwh Sum" Then _
Cells(1, delCol).EntireColumn.Delete
Next
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Name Me in Row 1
If Cells(1, delCol) = "Net KW" Then _
Cells(1, delCol).EntireColumn.Delete
Next
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Name Me in Row 1
If Cells(1, delCol) = "Net KWH" Then _
Cells(1, delCol).EntireColumn.Delete
Next
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Name Me in Row 1
If Cells(1, delCol) = "Total Lifetime Saving Units" Then _
Cells(1, delCol).EntireColumn.Delete
Next
End Sub