Results 1 to 20 of 27

Thread: How to list dates defined by a data validation process

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    1. This is tied to the WS Change event. I couldn't find an easy way to only use WS formulas

    2. I changed the DV and applied Custom Number formats; it made it a little easier to talk to the Sub

    3, Not sure I totally understood Objective 2, but let me know


    Option Explicit
    
    
    Sub UpdateChart()
        Dim iNumDays As Long, iTemp As Long, i As Long, o As Long
        Dim dateStart As Date, dateEnd As Date
        Dim rTemps As Range
        Dim rowStart As Long, rowEnd As Long
        
        With ActiveSheet
            If .ChartObjects.Count <> 1 Then Exit Sub
            
            Application.EnableEvents = False
    
    
            Set rTemps = .Range("A1").CurrentRegion
    
    
            iNumDays = .Range("G34").Value
            iTemp = .Range("G37")
            Range(.Range("I37"), .Range("I37").End(xlDown)).ClearContents
            .Range("I37").Value = "None"
            
    
    
            With rTemps
                If iNumDays > .Rows.Count Then iNumDays = .Rows.Count - 1
                rowStart = .Cells(.Rows.Count - iNumDays + 1, 1).Row
                rowEnd = .Cells(.Rows.Count, 1).Row
                dateStart = .Cells(rowStart, 1).Value
                dateEnd = .Cells(rowEnd, 1).Value
            End With
                
            o = 37
                
            For i = rowStart To rowEnd - 2
                If Abs(.Cells(i, 2).Value - iTemp) >= 3 And Abs(.Cells(i + 1, 2).Value - iTemp) >= 3 And Abs(.Cells(i + 2, 2).Value - iTemp) >= 3 Then
                    .Cells(o, 9).Value = .Cells(i, 1).Value
                    o = o + 1
                End If
            Next i
            
            With .ChartObjects(1).Chart
                .Axes(xlCategory).MinimumScale = CDbl(dateStart)
                .Axes(xlCategory).MaximumScale = CLng(dateEnd)
    
    
                .ChartTitle.Caption = "Temperature " & dateStart & " - " & dateEnd & Format(iNumDays, " (## days)")
            End With
    
    
            Application.EnableEvents = True
    
    
        End With
    
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •