Cell with data validation: Default to first item?

VBA_Newbie

Active Member
Joined
Jan 7, 2005
Messages
258
Hi folks,

I have a data validated cell which takes its valid entries from a dynamic named range. A macro I run changes the dynamic named range, and hence, the allowable entries of the data validated cell.

What I'm hoping to do is have the data validated cell 'default' to the first item in the dynamic named range everytime the macro is run. Any suggestions?

Many thanks in advance!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,

try this
Code:
Sub set_to_first_validationitem()
'Erik Van Geit
'050514 0108
Dim VF As String

    With Range("A1")
    VF = .Validation.Formula1
    .Value = Range(Right(VF, Len(VF) - 1))(1)
    End With

End Sub




kind regards,
Erik
 
Upvote 0
you're WELCOME :-)
now it would be intresting to understand how it works ...
when I was a Newbie, and even now (knowing there are other ways to do this), I'm using this technique
Code:
Sub set_to_first_validationitem()
'Erik Van Geit
'050514 0108
Dim VF As String

    With Range("A1")
    VF = .Validation.Formula1
    MsgBox VF, 64, "VF"
    MsgBox Right(VF, Len(VF) - 1), 64, "Right(VF, Len(VF) - 1)"
    MsgBox Range(Right(VF, Len(VF) - 1))(1).Address(0, 0), 64, "Range(Right(VF, Len(VF) - 1))(1).Address(0, 0)"
    MsgBox Range(Right(VF, Len(VF) - 1))(1).Value, 64, "Range(Right(VF, Len(VF) - 1))(1).Value"
    .Value = Range(Right(VF, Len(VF) - 1))(1)
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,395
Messages
6,178,349
Members
452,841
Latest member
GenAkaman

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