+ Reply to Thread
Results 1 to 9 of 9

Distribute allocation per month - Macro improvement

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Distribute allocation per month - Macro improvement

    Good afternoon

    Once again asking for help improving a Macro that I developed but it is taking a while to calculate

    So this is the problem I have:
    - I have tab GE_DF a set of tasks that have a certain assignment for a Start and End Date of the task;

    What I need:
    - Know for each month of Column "A" in DATAGraphicos, what is the total contribution of the percentages of allocations for each task and fill in Column "B"

    Already presenting the manual calculation made for the first 5 tasks and Macro to make this calculation in VBA, I also limited the calculation to the first 5 tasks just for testing.

    I think the routine is taking too long and my call for help is precisely to see if there is another faster method of doing what I want.

    Thank you
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: Distribute allocation per month - Macro improvement

    It looks like you could use a Pivot table for this, however, the data needs to be NORMALIZED (like it would need to be in a Database). I took your headings and added PERIOD to it. For Each task with multiple dates, I used the period (YYYYMM ~ YYYY = Year & MM~= Month)...by having this you can easily construct a pivot table that will get you your results. I included the TASK in the Pivot table for presentation, but you may not need it (and if you DELETE it my moving it off of the COLUMN Section [ drag it outside of Column Box in Pivot Table~ you will get your summarized results]). It's an approach that will work.

    Bueno suerte!
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Distribute allocation per month - Macro improvement

    Test my code
    PHP Code: 
    Sub Fill_table()
        
    Dim i As Integer
        Dim f 
    As StringAs StringAs String
        Dim rng_GE 
    As Rangerng_Data As Range
        
        With Sheets
    ("GE_DF")
            
    Set rng_GE = .Range("A17:H" & .Cells(Rows.Count"A").End(xlUp).Row)
        
    End With
        With Sheets
    ("DATAGraficos")
            
    Set rng_Data = .Range("A3:A" & .Cells(Rows.Count"A").End(xlUp).Row)
            For 
    1 To rng_GE.Rows.Count
                e 
    "'GE_DF'!" rng_GE.Cells(i5).Address
                f 
    "'GE_DF'!" rng_GE.Cells(i6).Address
                h 
    "'GE_DF'!" rng_GE.Cells(i8).Address
                With 
    .[C3].Resize(rng_Data.Rows.Count1).Offset(0i)
                    .
    Formula "=IF(AND(A3>=" ",A3<=" ")," ","""")"
                    
    .Value = .Value
                End With
            Next
        End With
        Set rng_Data 
    Nothing
        Set rng_GE 
    Nothing
    End Sub 
    Best Regards,
    Maras.

  4. #4
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Distribute allocation per month - Macro improvement

    Hi queuesef

    Thank you very much for your solution, but it is not possible to change the layout of the tab "GE_DF", which I show is part of a larger layout.

    What I need is just the total data per month, and then build a graph.

    Thanks for your solution

  5. #5
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Distribute allocation per month - Macro improvement

    Hi maras_mak

    Thank you so much for your solution.

    What I only want is the total per month, I only put the gray part to show how the calculation would be done if it was done manually.
    In the original spreadsheet, these columns do not exist so I just need the final result, which is in column "B" of "DATAGraphicos".

    Is it possible to adapt your code to give only the final result?

    Thank you very much

    Jorge Cabral

  6. #6
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Distribute allocation per month - Macro improvement

    Yes, of course, please ...
    PHP Code: 
    Sub Fill_table()
        
    Dim i As Integer
        Dim f 
    As StringAs StringAs String
        Dim rng_GE 
    As Rangerng_Data As Range
        
        With Sheets
    ("GE_DF")
            
    Set rng_GE = .Range("A17:H" & .Cells(Rows.Count"A").End(xlUp).Row)
        
    End With
        With Sheets
    ("DATAGraficos")
            
    Set rng_Data = .Range("A3:A" & .Cells(Rows.Count"A").End(xlUp).Row)
            For 
    1 To rng_GE.Rows.Count
                e 
    "'GE_DF'!" rng_GE.Cells(i5).Address
                f 
    "'GE_DF'!" rng_GE.Cells(i6).Address
                h 
    "'GE_DF'!" rng_GE.Cells(i8).Address
                With 
    .[C3].Resize(rng_Data.Rows.Count1).Offset(0i)
                    .
    Formula "=IF(AND(A3>=" ",A3<=" ")," ","""")"
                    
    .Value = .Value
                End With
            Next
            With 
    .[B3].Resize(rng_Data.Rows.Count1)
                    .
    Formula "=SUM(D3:BK3)"
                    
    .Value = .Value
                End With
        End With
        Set rng_Data 
    Nothing
        Set rng_GE 
    Nothing
    End Sub 

  7. #7
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Distribute allocation per month - Macro improvement

    Hi maras_mak

    Sorry I wasn't completely clear on the result I need.

    The columns, "C: BK" cannot exist, as they are here, as in my definitive layout, the columns have other values to make a graph.

    In this example I include those data only and exclusively to illustrate which result I intended to appear to me in column "B", total and final results, of the "DATAGraphics" tab.

    So I wanted to see the final values in column "B", and no partial values in the adjacent columns.

    Is it possible to do that?

    Thank you so much again
    Jorge

  8. #8
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Distribute allocation per month - Macro improvement

    My mistake. It will be fine now.
    PHP Code: 
    Sub Fill_table()
        
    Dim i As Integerii As Integerlr As Integer
        Dim a_GE
    (), a_DA()
        
        
    With Sheets("GE_DF")
            
    a_GE = .Range("E17:H" & .Cells(Rows.Count"A").End(xlUp).Row).Value
        End With
        With Sheets
    ("DATAGraficos")
            
    lr = .Cells(Rows.Count"A").End(xlUp).Row
            
    .Range("B3:B" lr 2).ClearContents
            a_DA 
    = .Range("A3:B" lr).Value
            
    For 1 To UBound(a_GE)
                For 
    ii 1 To UBound(a_DA)
                    If 
    a_DA(ii1) >= a_GE(i2) And a_DA(ii1) <= a_GE(i4Then _
                                                a_DA
    (ii2) = a_DA(ii2) + a_GE(i1)
                
    Next ii
            Next i
            
    .[B3].Resize(UBound(a_DA)) = Application.Index(a_DA02)
        
    End With
    End Sub 

  9. #9
    Registered User
    Join Date
    11-04-2014
    Location
    Portugal
    MS-Off Ver
    XL2013/XL365
    Posts
    88

    Re: Distribute allocation per month - Macro improvement

    PERFECT!

    Thank you so much again
    Jorge

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 12
    Last Post: 08-24-2019, 06:35 AM
  2. [SOLVED] Get date from listbox column and distribute day/month/year to comboboxes
    By ElStar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2018, 07:57 PM
  3. Month wise allocation
    By chandy123987 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2018, 06:07 AM
  4. Cost allocation based on days in month adding an extra day
    By rcm242 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-07-2017, 05:00 PM
  5. [SOLVED] Distribute/Allocate working days of the month accross multiple projects.
    By MuchieMac in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-27-2016, 04:50 AM
  6. Help needed to distribute a number over days of a month.
    By crimson_wolf in forum Excel General
    Replies: 5
    Last Post: 07-06-2012, 08:16 PM
  7. Pivot table improvement and formula improvement
    By constructionsheets in forum Excel General
    Replies: 0
    Last Post: 10-22-2011, 07:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1