Solved

Enhancement to Macro for Driving Dynamic Time Horizon

Posted on 2012-03-12
4
272 Views
Last Modified: 2012-03-12
I have a great macro/WS that DMille wrote for me that provides for a Dynamic Time Horizon. The attached model has the ability to add new "Use Cases" and when it does, the Time Horizon capability does not work correctly.  When the rows are replicated (i.e. click the + User Case button), and then you change the Time Horizons, the new User Cases do not respond accordingly.  The original one does but not the new ones.  I think it is because it is "hard coded" into the macro.  I think it's in these two reference points:

Set rngClear = Range("AJ2", Cells(4, Columns.Count)).Resize(6)
       
        rngClear.ClearContents
       
        numPeriods = Range("AB3")

Thank you in advance.....

B.
Workbench-v26.xlsm
0
Comment
Question by:Bright01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 37712082
I think I've sorted the problem, as the calculations need to be based on the Target row, while also keeping the timespan in row 2 expanded to the max needed based on any entry in AB.

Please try this code and advise:
'New code to expand months
Private Sub CheckExpMonths(ByVal Target As Range)
Dim numPeriods As Long
Dim periodDisplay As Long
Dim rngClear As Range
Dim LastCol As Long

    
    If Not Intersect(Target, Range("AB:AB")) Is Nothing Then
        Application.EnableEvents = False
        
        LastCol = Cells(4, Columns.Count).End(xlToLeft).Column
        
        Set rngClear = Range("AJ" & Target.Row - IIf(Target.Row = 3, 1, 0), Cells(Target.Row, Columns.Count)).Resize(6)
        
        rngClear.ClearContents
        
        numPeriods = Range("AB" & Target.Row)
        
        periodDisplay = Evaluate("=MAX(AB:AB)") 'get max periods to display
        If numPeriods > 1 Then
            With Range("AI2")
                .Resize(, periodDisplay).DataSeries Rowcol:=xlRows, Type:=xlChronological, Date:=xlMonth, Step:=1, Trend:=False
            End With
        End If
    
        Range("AI" & Target.Row & ":AI" & Target.Row + 1).Copy Range("AI" & Target.Row & ":AI" & Target.Row + 1).Resize(, numPeriods)
        
        Application.EnableEvents = True
    End If
            
End Sub

Open in new window


Dave
0
 

Author Closing Comment

by:Bright01
ID: 37712100
Dave,

That works!

Much thanks,

B.
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37712103
This post is more clever and uses the latest post from the prior question which for some reason you weren't.
'New code to expand months
Private Sub CheckExpMonths(ByVal Target As Range)
Dim numPeriods As Long
Dim periodDisplay As Long
Dim rngClear As Range
Dim LastCol As Long

    
    If Not Intersect(Target, Range("AB:AB")) Is Nothing Then
        Application.EnableEvents = False
        
        LastCol = Cells(4, Columns.Count).End(xlToLeft).Column
        
        Range("AJ2", Cells(2, Columns.Count)).ClearContents
        
        Set rngClear = Range("AJ" & Target.Row - IIf(Target.Row = 3, 1, 0), Cells(Target.Row, Columns.Count)).Resize(3)
        
        rngClear.ClearContents
        
        numPeriods = Range("AB" & Target.Row).Value
        
        periodDisplay = Evaluate("=MAX(AB:AB)") 'get max periods to display
        If numPeriods >= 1 Then
            With Range("AI2")
                .Resize(, periodDisplay).DataSeries Rowcol:=xlRows, Type:=xlChronological, Date:=xlMonth, Step:=1, Trend:=False
            End With
            Range("AI" & Target.Row & ":AI" & Target.Row + 1).Copy Range("AI" & Target.Row & ":AI" & Target.Row + 1).Resize(, numPeriods)
        End If
        
        Application.EnableEvents = True
    End If
            
End Sub

Open in new window


Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37712107
Bright - you need to use the latest post, above.  After more testing more tweaks were necessary.

Dave
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question