VBA to Reset multiple Data Validation lists to first entry in list

Sheripres

Board Regular
Joined
Sep 7, 2011
Messages
94
Hello:
I found a VBA code that was strictly for lists and would not work for me. My data validation lists/drop downs are created with many formulas and some that are just lists.
After the end user creates the part number through the various drop downs, they push a button and it pastes on another sheet tab.
Now, I want to reset what they put on the Form sheet tab so they can start over. I will just create another form button.

Thank you for any help.

Sheri
 
Sorry, I don't know what list separator you're using. Is it comma or semicolon? If it is comma then replace:
VBA Code:
ListCell.Value = Split(ListCell.Validation.Formula1, ";")(0)
with:
VBA Code:
ListCell.Value = Split(ListCell.Validation.Formula1, ",")(0)
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think you're using string as the list., something like: apel;lemon;banana
Try this one:
VBA Code:
Sub ResetDropDowns_1()

Dim rngLists As Range
Dim ListCell As Range
Dim c As Range

On Error Resume Next
Set rngLists = ActiveSheet.UsedRange.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0

If Not rngLists Is Nothing Then
    For Each ListCell In rngLists.Cells
            If IsError(Evaluate(ListCell.Validation.Formula1)) Then
                ListCell.Value = Split(ListCell.Validation.Formula1, ";")(0)
            Else
                Set c = Evaluate(ListCell.Validation.Formula1)
                If Not c Is Nothing Then ListCell.Value = c.Cells(1)
            End If
    Next ListCell
End If

End Sub
Almost there! Works perfectly for the IF statements, but the first validation list combines all three choices instead of just CHOOSE THERMOSTAT MODEL.

If there is not a fix for it, I can create a fake IF statement for this somehow.

THANK YOU so much for helping! :)

1690210059052.png
 
Upvote 0
I think you're using string as the list., something like: apel;lemon;banana
Try this one:
VBA Code:
Sub ResetDropDowns_1()

Dim rngLists As Range
Dim ListCell As Range
Dim c As Range

On Error Resume Next
Set rngLists = ActiveSheet.UsedRange.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0

If Not rngLists Is Nothing Then
    For Each ListCell In rngLists.Cells
            If IsError(Evaluate(ListCell.Validation.Formula1)) Then
                ListCell.Value = Split(ListCell.Validation.Formula1, ";")(0)
            Else
                Set c = Evaluate(ListCell.Validation.Formula1)
                If Not c Is Nothing Then ListCell.Value = c.Cells(1)
            End If
    Next ListCell
End If

End Sub
GOT IT! I just had to change the ";" to "," since it was a string.

Thank you so much!!! This is a life saver for me!
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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