Search through worksheets excluding some

Eai

New Member
Joined
Oct 10, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Greetings All, Very beginner here. Thanks in advance for any help anyone can give me. I’ve searched through this forum and haven’t come up with a solution to my issue.

I'm trying to search all worksheets, with the exception of three ("MASTER", "CUSTOMER" and "AVAILABLE"), clear specific cells in the remaining sheets if they meet a specific test. The cells I want to search are in each worksheet in cells "D7:D9". If they are equal to or less than today’s date, I what to clear the cell. I get an error code "Invalid Next Control” on the NEXT I statement. Any thoughts on what I'm missing? Sorry but I’m not 100% sure on how to upload code to a post.

VBA Code:
Sub DeleteDatesAA()

Dim WS_Count As Integer
Dim I As Integer
    ' Set WS_Count equal to the number of worksheets in the active workbook.
WS_Count = ActiveWorkbook.Worksheets.Count
     ' Begin the loop.
For I = 1 To WS_Count
If ws.Name <> "MASTER" Or ws.Name <> "CUSTOMER" Or ws.Name <> "AVAILABLE" Then
Else
For Each cell In ws.Range("D7:D9")
     ' If the cell date is TODAY or after TODAY for the Return date
If Sheet.Cells(9, 4).Value < (Date + 1) Then
     ' Clear the contents of Return date
cell.ClearContents
End If
Next I
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi. Try this code, please.
VBA Code:
Sub DeleteDatesAA()
 Dim ws As Worksheet, cell As Range
  For Each ws In ThisWorkbook.Worksheets
   If ws.Name <> "MASTER" And ws.Name <> "CUSTOMER" And ws.Name <> "AVAILABLE" Then
    For Each cell In ws.Range("D7:D9")
     If cell.Value < (Date + 1) Then cell.Value = ""
    Next cell
   End If
  Next ws
End Sub
 
Upvote 0
Here is my suggestion:
VBA Code:
Sub DeleteDatesAA()
 'Modified  10/10/2021  9:37:07 AM  EDT
Application.ScreenUpdating = False
 Dim ws As Worksheet, cell As Range
  For Each ws In ThisWorkbook.Worksheets
   
   Select Case ws.Name
    Case "MASTER", "CUSTOMER", "AVAILABLE"
   
    Case Else
        For Each cell In ws.Range("D7:D9")
            If cell.Value <= (Date) Then cell.Value = ""
        Next cell
    End Select
  Next ws
Application.ScreenUpdating = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top