Excel VBA : assign formula to multiples dynamic range table in same sheet -
i new , learning excel vba. having problem
- there more 10 tables in worksheet (number of tables not consistent)
- the number of columns consistent not rows in each tables
- i apply total row end of every table
- after that, apply same formula every table , put results on right side of each table
this easy core problem range unknown. - not actual table in excel, tried first define range of data creating table it, again, don't have idea on how create table without knowing range.
below came (which not "dynamic")
sub plswork() set u = thisworkbook.worksheets("sheet2") set f = u.range("a").find(what:="name", lookat:=xlpart) = f.address set sht = u.range(a) 'trying insert @ end of table total = sum(u.offset(2, 1) + u.offset(3, 1) + u.offset(4, 1)) if cells(i, 2) = vbnullstring 'this not applicable top 2 row in colb has null string u.offset(i, 1).value = total 'putting table name @ f2 u.offset(-2, 5).value = u.offset(-3, 0).value u.offset(-2, 6).value = total u.offset(-1, 5).value = u.offset(2, 0).value u.offset(-1, 6).value = sum(u.offset(2, 1) + u.offset(2, 2) + u.offset(2, 3)) u.offset(0, 5).value = u.offset(3, 0).value u.offset(0, 6).value = sum(u.offset(3, 1) + u.offset(3, 2) + u.offset(3, 3)) u.offset(1, 5).value = u.offset(4, 0).value u.offset(1, 6).value = sum(u.offset(4, 1) + u.offset(4, 2) + u.offset(4, 3)) end sub
oh, , when run above code, got error "sub or function not defined" on "sum"
here image of tables in sheet
yellow highlighted going there after executing sub.
it quite easy applying formula in excel sheet , copy paste formula each tables,
tedious, try come out vba code macro run based on schedule.
i'm scratching head , searching , fro past 2 days, still haven't got clue on how code this.
can expert tell me if possible? without knowing range?
if so, guys shed me info on how achieve this?
thank you. want know if can done or not.
you may try this...
the code below insert total row each table has more 1 row , 4 columns in it.
sub inserttotalineachtable() dim ws worksheet dim rng range dim integer, r long, j long application.screenupdating = false set ws = activesheet each rng in ws.usedrange.specialcells(xlcelltypeconstants, 3).areas if rng.rows.count > 1 , rng.columns.count = 4 j = 2 r = rng.cells(rng.rows.count, 1).row + 1 cells(r, rng.columns(1).column).value = "total" = rng.columns(2).column rng.columns(2).column + 2 cells(r, i).formula = "=sum(" & rng.columns(j).address & ")" j = j + 1 next end if next rng application.screenupdating = true end sub
Comments
Post a Comment