RESETING DROPDOWNS

JamRivera

New Member
Joined
Jun 9, 2019
Messages
34
Hi Akuiuni, how do i make the macro search for NO and TIP so if found it will reset to YES? Thank you for all your help.
VBA Code:
Function isValid(c As Range) As Boolean
Dim v

On Error Resume Next
v = c.Validation.Type
On Error GoTo 0

isValid = Not IsEmpty(v)
End Function

Sub JamRivera()

Dim c As Range
Dim sAddress As String

For Each x In Array("Sheet1", "Sheet2")
With Sheets(x).Range("A1:V45")
Set c = .Find(What:="No", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
sAddress = c.Address
Do
Set c = .FindNext(c)
If isValid(c) Then c = "Yes"
Loop While Not c Is Nothing And c.Address <> sAddress
End If
End With
Next

End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
how do i make the macro search for NO and TIP so if found it will reset to YES?
Try:
VBA Code:
Sub JamRivera2()

Dim c As Range, x, y
Dim sAddress As String
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each x In Array("Sheet1", "Sheet2")
    With Sheets(x).Range("A1:V45")
        For Each y In Array("NO", "TIP")
        Set c = .Find(What:=y, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If Not c Is Nothing Then
            sAddress = c.Address
            Do
               Set c = .FindNext(c)
               If isValid(c) Then c = "Yes"
            Loop While Not c Is Nothing And c.Address <> sAddress
        End If
        Next
    End With


Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

or if you are searching on all sheets then you don't have to specify the sheets, like this:
VBA Code:
Sub JamRivera3()

Dim c As Range, y
Dim sAddress As String
Dim ws As Worksheet
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
    With ws.Range("A1:V45")
        For Each y In Array("NO", "TIP")
        Set c = .Find(What:=y, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If Not c Is Nothing Then
            sAddress = c.Address
            Do
               Set c = .FindNext(c)
               If isValid(c) Then c = "Yes"
            Loop While Not c Is Nothing And c.Address <> sAddress
        End If
        Next
    End With
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thank You the last code work perfectly :)
VBA Code:
Sub JamRivera3()

Dim c As Range, y
Dim sAddress As String
Dim ws As Worksheet
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
With ws.Range("A1:V45")
For Each y In Array("NO", "TIP")
Set c = .Find(What:=y, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
sAddress = c.Address
Do
Set c = .FindNext(c)
If isValid(c) Then c = "Yes"
Loop While Not c Is Nothing And c.Address <> sAddress
End If
Next
End With
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0
Hi Akuini again thanks for all your help just need a little bit more help :)
I ran the macro yesterday and it worked just fine but I tried today and i get the following error
Compile error: sub or function not defined - stops at isValid highlighted in blue below?
BTW I didn't make changes to the macro and the only issue is resetting the drop downs to a YES if drop down is a NO or TIP


1634676865191.png
 
Last edited:
Upvote 0
You must have the "Function isValid(c As Range) As Boolean" (in post #1), do not remove it.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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