Link to home
Start Free TrialLog in
Avatar of Flora Edwards
Flora EdwardsFlag for Sweden

asked on

Simple Macro but is a big challenge. any Expert can solve this please?

please see attached file and the screenshot below.

it maybe require a simple modification to the code, but looks very challenging.

User generated imageEE.xlsb
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Flora Edwards

ASKER

Rgonzo1971   this is great!   Thanks a million.  very much appreciated.
Rgonzo1971


thanks alot. it has one small issue.

if i have two or three more years with blank cells, it also fills them as well. while it should not.

for example please see attached.
User generated imageEE.xlsb
Avatar of Rgonzo1971
Rgonzo1971

then try
Sub MacroAll()
Dim Main As Worksheet

    Set Main = Sheets("Main")
    Set ShD = Sheets("NewData")

    intYearCol = Range("dataYear").Column
    intMonthCol = Range("dataMonth").Column
    intProductCol = Range("dataPRODUCT").Column
    intAmountCol = Range("dataAMOUNT").Column

    For Each cl In Range(Main.Range("B3"), Main.Range("F3"))
        mySum = 0
        Application.StatusBar = "Processing month " & Main.Cells(cl.Row, 1).Value & " for year " & Main.Cells(2, cl.Column).Value
        For Each c In Range(ShD.Range("a2"), ShD.Range("a" & Rows.Count).End(xlUp))

            If ShD.Cells(c.Row, intYearCol).Value = (Main.Cells(2, cl.Column).Value2 * 1) And ShD.Cells(c.Row, intMonthCol).Value = (Main.Range("A" & cl.Row).Value2 * 1) _
               And ShD.Cells(c.Row, intMonthCol).Value <> 111 And _
               ShD.Cells(c.Row, intProductCol).Value Like "[5-7]*" Then
                mySum = mySum + ShD.Cells(c.Row, intAmountCol).Value
            End If
        Next
        mySumReported = mySumReported + mySum - cl.Value
        If cl.Value = 0 And mySumReported <> 0 Then
            cl.Value = mySumReported
            mySumReported = 0
        End If
    Next

    Application.StatusBar = False

End Sub

Open in new window

PERFECT!    worked perfectly.  thanks alot
posted a follow up question