I have written code to clear data from row 4 onwards and to include columns A:B, C:D only and to ignore the last three sheets
I only need to data clear up to o1 row before where "Total" appears in Col A
However, when activating the code , I get a message compile error: Invalid next control variance reference and next I is highlighted
Your assistance in resolving this is most appreciated
Code:Sub Clear_data() Dim i As Long For i = 1 To Worksheets.Count - 3 Dim MyBook As Workbook Dim Sht As Worksheet Dim RangeToErase As Range Dim YTDTotal As Range Set MyBook = ThisWorkbook For Each Sht In MyBook.Worksheets Set YTDTotal = Sht.Range("A:A").Find("Total") With Worksheets(i) LR = .Range("A" & Rows.Count).End(xlUp).Row End With If Not YTDTotal Is Nothing Then Sht.Range("A4:b" & YTDTotal.Row - 1).Clear Sht.Range("D4:D" & YTDTotal.Row - 1).Clear End If Next i Next Sht End Sub


Reply With Quote

Bookmarks