Data validation automatically set to first item in list

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234
Morning sirs,

I've been having a good look around for this, but am struggling to find a solution that works.

I have various data validation lists, and would like them automatically to be set to their first value when they are set up (uses a macro). Does anyone have any idea how this might be done?

Thanks in advance,

dirtychinchilla
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
It's having trouble with this bit:

Code:
 .Value = Range(Range(Replace(Replace(.Validation.Formula1, "=INDIRECT(", ""), ")", "")).Value).Cells(1, 1).Value
 
Upvote 0
Maybe the order in which the Data validation was created is important:

Code:
Sub Test()
    Dim Cell As Range
    For Each Cell In ActiveSheet.Cells.SpecialCells(xlCellTypeAllValidation).Cells
        With Cell
            If .Validation.Type = xlValidateList Then
                If InStr(.Validation.Formula1, "=INDIRECT") = 0 Then
                    .Value = Range(Replace(.Validation.Formula1, "=", "")).Cells(1, 1).Value
                End If
            End If
        End With
    Next Cell
    For Each Cell In ActiveSheet.Cells.SpecialCells(xlCellTypeAllValidation).Cells
        With Cell
            If .Validation.Type = xlValidateList Then
                If InStr(.Validation.Formula1, "=INDIRECT") > 0 Then
                    .Value = Range(Range(Replace(Replace(.Validation.Formula1, "=INDIRECT(", ""), ")", "")).Value).Cells(1, 1).Value
                End If
            End If
        End With
    Next Cell
End Sub
 
Upvote 0
I can't reproduce the error. What does then name UnitTypeTran refer to and what's in the reference when the error occurs?
 
Upvote 0
How strange.

UnitTypeTran refers to the unit type, and has the following formula in it:

=VLOOKUP(UnitType,Unit_Code_Turndown,5,FALSE)

This would have something in it like AM_300 at the time the code goes through.
 
Upvote 0

Forum statistics

Threads
1,215,471
Messages
6,125,000
Members
449,202
Latest member
Pertotal

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