vba - Need a loop to enter formulas/data in excel table columns -


i in need of nested loop add formulas 4 particular columns in table ("table1"). loop mimic previous loop regarding naming of these same 4 additional columns ("colnames").

the bottom portion of code works fine, know how work loop.

sub attstatpivinserttablecolumns_2() dim lst listobject dim currentsht worksheet dim colnames variant, formnames variant '<~~ note: varient, go when working arrays dim olc listcolumn, oldata variant dim integer, d integer  set currentsht = activeworkbook.sheets("sheet1") set lst = activesheet.listobjects("table1")  colnames = array("aht", "target aht", "transfers", "target transfers")      = 0 ubound(colnames)          set olc = lst.listcolumns.add         olc.name = colnames(i)     next           ***below code needs looped***                                 'lst.listcolumns("target aht").databodyrange.formular1c1 = "=350" 'lst.listcolumns("target transfers").databodyrange.formular1c1 = "=0.15" 'lst.listcolumns("aht").databodyrange.formular1c1 = "=([@[inbound talk time (seconds)]]+[@[inbound hold time (seconds)]]+[@[inbound wrap time (seconds)]])/[@[calls handled]]" 'lst.listcolumns("transfers").databodyrange.formular1c1 = "=[@[call transfers and/or conferences]]/[@[calls handled]]"  end sub 

here going far, running errors, obvious reasons:

formnames = array("=([@[inbound talk time (seconds)]]+[@[inbound hold time (seconds)]]+[@[inbound wrap time (seconds)]])/[@[calls handled]]", "=350", "=[@[call transfers and/or conferences]]/[@[calls handled]]", "=0.15") d = 0 ubound(formnames)     = 0 ubound(colnames)         set oldata = lst.listcolumns(i).databodyrange.formular1c1 = "d"     next next d 

construct 1 more variant array containing formulas/values want populate new table columns with.

sub inserttablecolumn()     dim lst listobject     dim currentsht worksheet     dim h long, hdrs variant, r1c1s variant      hdrs = array("aht", "target aht", "transfers", "target transfers")     r1c1s = array("=([@[inbound talk time (seconds)]]+[@[inbound hold time (seconds)]]+[@[inbound wrap time (seconds)]])/[@[calls handled]]", _                     350, _                     "=[@[call transfers and/or conferences]]/[@[calls handled]]", _                     0.15)      set currentsht = activeworkbook.sheets("sheet1")     set lst = activesheet.listobjects("table1")      lst 'activesheet.listobjects("table1")         h = lbound(hdrs) ubound(hdrs)             .listcolumns.add             .listcolumns(.listcolumns.count).name = hdrs(h)             .listcolumns(.listcolumns.count).databodyrange.formular1c1 = r1c1s(h)         next h     end  end sub 

i've used pairs in single array h = lbound(hdrs) ubound(hdrs) step 2 , hdrs(h+1) formulas/values.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo