Automate assigned Data Validations

emergguy

New Member
Joined
Sep 3, 2023
Messages
8
Office Version
  1. 365
Platform
  1. MacOS
I am so impressed with the responses I thought I'd try another puzzle I haven't been able to solve.

In short, the sheet is designed to manually populate a schedule.
For each day, there are various manpower availabilities - and the available names are in named ranges (ie _Jan1, _Jan2 etc) : (also shown with colours for ease of explanation).
I have manually prepopulated the Data Validations for Row 3 and Row 4, pointing each Data Validation range to its corresponding Named Range.

The question:
Since The schedule is filled for 3-4 months at a time, manually assigning the Data Validation range to each row(date) is time-consuming (and prone to error when keystroke fatigue sets in)
Is it possible to automate this - either by formula or a VBA script? (I am very new, but aim to dissect formulas and scripts when I can so I can learn more)

Much appreciated if anyone thinks this possible.
Book2.xlsx
ABCDE
1
2DayShift 1Shift 2Shift 3
31-Jan
42-Jan
53-Jan
64-Jan
75-Jan
8
9Availabilities
10_Jan1_Jan2_Jan3_Jan4_Jan5
11
12Doc ADoc ADoc CDoc ADoc A
13Doc BDoc CDoc DDoc EDoc B
14Doc CDoc DDoc EDoc FDoc C
15Doc DDoc EDoc FDoc D
16Doc EDoc E
17Doc F
Sheet1
Cells with Data Validation
CellAllowCriteria
B3:D3List=_Jan1
B4:D4List=_Jan2
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The question:
Since The schedule is filled for 3-4 months at a time, manually assigning the Data Validation range to each row(date) is time-consuming (and prone to error when keystroke fatigue sets in)
Is it possible to automate this - either by formula or a VBA script?
Where is "availabilities" actually located? Is it in the same sheet (i.e. Sheet1)?
 
Upvote 0
Where is "availabilities" actually located? Is it in the same sheet (i.e. Sheet1)?
My apologies Akuini, I can see how the defined Named Ranges are unclear in my post.

Availabilities for each day are the Named Ranges ie _Jan1 = A12-A17, _Jan2 = B12:15
So
Jan1, the DataValidations for B3:D3 should be A12:A17
Jan2, the DataValidations for B4:D4 should be B12:B15

Thanks for your interest,
 
Upvote 0
I assumed that the named ranges already exist.
Try this:
VBA Code:
Sub emergguy_1()
Dim c As Range, i As Long
For Each c In Range("B3:B7")
    With c.Resize(, 3).Validation
        .Delete 'delete previous validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Formula1:="=" & Range("A10").Offset(, i).Value
        i = i + 1
    End With
Next
End Sub
 
Upvote 0
Solution
I assumed that the named ranges already exist.
Try this:
VBA Code:
Sub emergguy_1()
Dim c As Range, i As Long
For Each c In Range("B3:B7")
    With c.Resize(, 3).Validation
        .Delete 'delete previous validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Formula1:="=" & Range("A10").Offset(, i).Value
        i = i + 1
    End With
Next
End Sub
Perfect! Works like a charm.
Off to dissect the code and learn some more.
Much appreciated!
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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