Hi Masters of Excel,
I can't seem to find a way to have my code loop through all sheets in a workbook. I've never worked with loops before. What I have tried only goes to sheet 2 so I have removed that. Any thoughts to get me in the right direction. Here is the code I am hoping to execute on each sheet (up to 80 sheets in the workbook).
I can't seem to find a way to have my code loop through all sheets in a workbook. I've never worked with loops before. What I have tried only goes to sheet 2 so I have removed that. Any thoughts to get me in the right direction. Here is the code I am hoping to execute on each sheet (up to 80 sheets in the workbook).
Code:
Sub ReviseTime()
'
' ReviseTime Macro
'
' Keyboard Shortcut: Ctrl+r
'
'Removes rows with specific text
Dim i As Long
Dim Ary As Variant
Ary = Array("Other", "Total")
For i = 0 To UBound(Ary)
With Range("C5", Range("C" & Rows.Count).End(xlUp))
.Replace "*" & Ary(i) & "*", True, xlPart, , False, , False, False
On Error Resume Next
.SpecialCells(xlConstants, xlLogical).EntireRow.Delete
On Error GoTo 0
End With
With Range("D5", Range("D" & Rows.Count).End(xlUp))
.Replace "*" & Ary(i) & "*", True, xlPart, , False, , False, False
On Error Resume Next
.SpecialCells(xlConstants, xlLogical).EntireRow.Delete
On Error GoTo 0
End With
Next i
'Replace numbers greater than 4
Columns("P:P").Select
Selection.Replace What:="1", Replacement:="1", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="2", Replacement:="2", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="3", Replacement:="3", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="4", Replacement:="4", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="5", Replacement:="4", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="6", Replacement:="5", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="7", Replacement:="6", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="9", Replacement:="8", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("R7").Select
ActiveCell.FormulaR1C1 = "=SUM(C[-2])"
Range("R8").Select
End Sub
Last edited by a moderator: