Want To Change Formula To Vba Array & Dictionary

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear All Master,
I want to change the formula to vba array and dictionary because there are 350000 records and I also use add custom columns in power query so excel formulas don't run automatically so my solution is to use vba.
for information my sheet name is "GSG" and my table name is "GSG_ALL"
Formula in column AD
Excel Formula:
=IF(AA2="SALES",IF(M2<=25000,M2+V2,0),"")
Formula in column AE
Excel Formula:
=IF(M2+P2+V2=0,"",IF(AA2="STOCK OPNAME","",IF(AA2="CHANGE ART","",IF(AA2="ITEM TRANSFER","",ROUND(IF(AA2="SALES",(M2+V2-AD2)/P2*100),1)))))
WANT TO CHANGE FORMULA TO VBA ARRAY & DICTIONARY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
1CSBGDNPNMDTSDUDSACOBYABYDSCPINPNPPONDISPOSSLSBLCPKPPDOPIVCDDRCVDIS2DEPTOPTTOTALNAMEGROUP DATAREF CAMUSCUSTOMER NAMECASHDISCOUNT%dis
2FGD0001TEST1211000101/10/202101/10/202110000A00SONONE200000TRUE1000000FALSE0FALSE40000BOJ01000000ASALESSTOREA024.00
3FGD0001TEST1211000202/10/202102/10/202110001A00SONONE30000TRUE200000FALSE0FALSE29400BOJ0200000BSALESSTOREB029.70
4FGD0001TEST1211000303/10/202103/10/202110002A00SONONE45000TRUE300000FALSE0FALSE0BOJ0300000CSALESSTOREC015.00
5FGD0001TEST1211000404/10/202104/10/202110003A00SONONE35000TRUE500000FALSE0FALSE0BOJ0500000DSALESSTORED07.00
6FGD0001TEST1211000505/10/202105/10/202110004A00SONONE25000TRUE250000FALSE10FALSE0BOJ0250000ESALESSTOREE250000.00
7FGD0001TEST1211000605/10/202105/10/202110005A00SONONETRUE100000FALSE0FALSE0BOJ0100000FITEM TRANSFERSTOREF  
8FGD0001TEST1211000705/10/202105/10/202110006A00SONONETRUE20000FALSE0FALSE0BOJ020000GSTOCK OPNAMESTOREG  
9FGD0001TEST1211000805/10/202105/10/202110007A00SONONETRUE20000FALSE0FALSE0BOJ020000HCHANGE ARTSTOREH  
GSG
Cell Formulas
RangeFormula
AD2:AD9AD2=IF(AA2="SALES",IF(M2<=25000,M2+V2,0),"")
AE2:AE9AE2=IF(M2+P2+V2=0,"",IF(AA2="STOCK OPNAME","",IF(AA2="CHANGE ART","",IF(AA2="ITEM TRANSFER","",ROUND(IF(AA2="SALES",(M2+V2-AD2)/P2*100),1)))))

Thanks
roykana
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You can add the last two columns using Power Query. The code below adds the columns, as described, to your table (starting without columns AD and AE):

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="GSG_ALL"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"CSB", type text}, {"GDN", Int64.Type}, {"PNM", type text}, {"DTS", Int64.Type}, {"DUD", Int64.Type}, {"SAC", Int64.Type}, {"OBY", type text}, {"ABY", type any}, {"DSC", type any}, {"PIN", Int64.Type}, {"PNP", Int64.Type}, {"PON", type text}, {"DIS", Int64.Type}, {"POS", type logical}, {"SLS", type any}, {"BLC", Int64.Type}, {"PKP", type logical}, {"PDO", type any}, {"PIV", Int64.Type}, {"CDD", Int64.Type}, {"RCV", type logical}, {"DIS2", Int64.Type}, {"DEPT", type text}, {"OPT", Int64.Type}, {"TOTAL", Int64.Type}, {"NAME", type text}, {"GROUP DATA", type text}, {"REF CAMUS", type text}, {"CUSTOMER NAME", type text}}),
    tbl1 = Table.AddColumn(Type,"CASHDISCOUNT", each 
        if [GROUP DATA] = "SALES" then if [DIS] <= 25000 then [DIS] + [DIS2] else 0 else null),
    tbl2 = Table.AddColumn(tbl1,"%dis", each 
        if [DIS] + [BLC] +[DIS2] = 0 then null else
            if [GROUP DATA] = "STOCK OPNAME" then null else 
                if [GROUP DATA] = "CHANGE ART" then null else
                    if [GROUP DATA] = "ITEM TRANSFER" then null else
                        Number.Round(if [GROUP DATA] ="SALES" then ([DIS] + [DIS2] - [CASHDISCOUNT])*100/[BLC] else 1,2))
in
    tbl2
 
Upvote 0
Solution
You can add the last two columns using Power Query. The code below adds the columns, as described, to your table (starting without columns AD and AE):

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="GSG_ALL"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"CSB", type text}, {"GDN", Int64.Type}, {"PNM", type text}, {"DTS", Int64.Type}, {"DUD", Int64.Type}, {"SAC", Int64.Type}, {"OBY", type text}, {"ABY", type any}, {"DSC", type any}, {"PIN", Int64.Type}, {"PNP", Int64.Type}, {"PON", type text}, {"DIS", Int64.Type}, {"POS", type logical}, {"SLS", type any}, {"BLC", Int64.Type}, {"PKP", type logical}, {"PDO", type any}, {"PIV", Int64.Type}, {"CDD", Int64.Type}, {"RCV", type logical}, {"DIS2", Int64.Type}, {"DEPT", type text}, {"OPT", Int64.Type}, {"TOTAL", Int64.Type}, {"NAME", type text}, {"GROUP DATA", type text}, {"REF CAMUS", type text}, {"CUSTOMER NAME", type text}}),
    tbl1 = Table.AddColumn(Type,"CASHDISCOUNT", each
        if [GROUP DATA] = "SALES" then if [DIS] <= 25000 then [DIS] + [DIS2] else 0 else null),
    tbl2 = Table.AddColumn(tbl1,"%dis", each
        if [DIS] + [BLC] +[DIS2] = 0 then null else
            if [GROUP DATA] = "STOCK OPNAME" then null else
                if [GROUP DATA] = "CHANGE ART" then null else
                    if [GROUP DATA] = "ITEM TRANSFER" then null else
                        Number.Round(if [GROUP DATA] ="SALES" then ([DIS] + [DIS2] - [CASHDISCOUNT])*100/[BLC] else 1,2))
in
    tbl2
Dear Mr.JGordon11

thank you very much and your power query code works perfectly.

Thanks
roykana
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top