I have this code below,
now if i have to modify this, add more conditions. for example more years to include for example instead of many OR and AND functions, i simply want to use an array for example lets say if i have more years to add then i simply use the {2002, 2011, 2012, 2013, 2014, 2015,} for year like this ShD.Cells(C.Row, intYearCol).Value = {2002, 2011, 2012, 2013, 2014, 2015,} and for months to exclude ShD.Cells(C.Row, intMonthCol).Value <> {111, XI, XII, XXII}
thanks.
Code:Sub macro3() intYearCol = Range("dataYear").Column intMonthCol = Range("dataMonth").Column intProductCol = Range("dataPRODUCT").Column intAmountCol = Range("dataAMOUNT").Column Set ShD = Sheets("Data") For Each C In Range(ShD.Range("a2"), ShD.Range("a" & Rows.Count).End(xlUp)) If (ShD.Cells(C.Row, intYearCol).Value = 2011 Or ShD.Cells(C.Row, intYearCol).Value = 2012) _ 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 Sheets("Main").Range("B3") = mySum End Sub


Reply With Quote

Bookmarks