Interval and Frequency Timing

Bright01
Bright01 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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

Older than dirt
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
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

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
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

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.
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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
No problem, B.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial