Interval and Frequency Timing

I am looking for a solution that was noted in post 40952095 which has to do with the ability for a Frequency selection to always be less in time then the Interval it is contained in.

 

For example, if the Interval Metric were 'Day' then the only choices for Frequency Measure should be 'Second', 'Minute', 'Hour' and 'Day'.

Thank you,

B.
D--Data-Data-Temp-Interval-and-Freq.xlsm
Bright01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Don't allow the coice of a Frequency Measure to be a longer time period
' than the Interval Metric
Dim strEndCol As String
If Not Intersect(Target, Range("C11")) Is Nothing Then
    With Target.Validation
        .Delete
        Select Case Target.Offset(-1, 0)
            Case "Second"
                strEndCol = "C"
            Case "Minute"
                strEndCol = "D"
            Case "Hour"
                strEndCol = "E"
            Case "Day"
                strEndCol = "F"
            Case "Week"
                strEndCol = "G"
            Case "Month"
                strEndCol = "H"
            Case "Year"
                strEndCol = "I"
        End Select
         .Add Type:=xlValidateList, Formula1:="=C56:" & strEndCol & "56"
    End With
End If

Open in new window

0
Martin LissOlder than dirtCommented:
It actually works better in the Worksheet_Change because when there I can remove the Frequency Measure if the change to the Interval Metric makes the Frequency Measure invalid. For example if the Frequency was 'Day' and the Metric was changed to 'Hour' then the code removes the Frequency because it's not valid.

Private Sub Worksheet_Change(ByVal Target As Range)
' Don't allow the coice of a Frequency Measure to be a longer time period
' than the Interval Metric
Dim strEndCol As String
Dim cel As Range
Dim bFound As Boolean

If Not Intersect(Target, Range("C10")) Is Nothing Then
    With Target.Offset(1, 0).Validation
        .Delete
        Select Case Target '.Offset(-1, 0)
            Case "Second"
                strEndCol = "C"
            Case "Minute"
                strEndCol = "D"
            Case "Hour"
                strEndCol = "E"
            Case "Day"
                strEndCol = "F"
            Case "Week"
                strEndCol = "G"
            Case "Month"
                strEndCol = "H"
            Case "Year"
                strEndCol = "I"
        End Select
        .Add Type:=xlValidateList, Formula1:="=C56:" & strEndCol & "56"
        For Each cel In Range(Target.Offset(1, 0).Validation.Formula1)
            If cel.Value = Target.Offset(1, 0) Then
               bFound = True
               Exit For
            End If
        Next
        If Not bFound Then
            Range("C11") = ""
        End If
    End With
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
[ fanpages ]IT Services ConsultantCommented:
Hi again B.

If you can confirm what should be shown in cell [C7] ("Frequency Measure") if "Second" is in cell [C6] "Interval Metric", then I can adjust this suggestion accordingly.

However, I have placed the following Data Validation formula in cell [C7] ("Frequency Measure"):

=INDIRECT("$C$52:"&ADDRESS(52,1+IF(MATCH(C6,C52:I52,0)<2,2,MATCH(C6,C52:I52,0))))

No other changes are necessary to the workbook, or to the Visual Basic for Applications code.

(If "Second" is in cell [C6], "Second" can also be selected in cell [C7]; this may not be as you intended)

Please see the attached workbook.
Q-28709554.xlsm
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Bright01Author Commented:
Thanks guys!  I ran through both solutions and they both work as far as I can tell.  Martin, you were in first and the refinement looks good.  Fanpages, thanks as always in also providing a solution.

You guys are great.

B.
1
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
0
[ fanpages ]IT Services ConsultantCommented:
No problem, B.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.