excel - VBA || Transpose unique values and Sums -
i'm trying make map transposes unique values column , populate new list parameters table,
the result on map should following
i've have code unique values follows:
dim d object dim c variant dim long dim lr long set d = createobject("scripting.dictionary") lr = cells(rows.count, 9).end(xlup).row c = range("b2:b" & lr) = 1 ubound(c, 1) d(c(i, 1)) = 1 next range("ak2").resize(d.count) = application.transpose(d.keys) although filling amounts on columns base , vat i'm having issues trying think on formula, "base" value should total document nr of accounts starting 6*,7* result of dr - cr.
i know may sound bit confusing, if please me appreciated.
using @ronrosenfeld formula comments, following might helpful:
sub demo() dim lastrow long, lastcol long, currlr long dim rng range, rngwh range dim srcsht worksheet application.screenupdating = false application.calculation = xlcalculationmanual set srcsht = sheets("sheet1") 'set data sheet here srcsht lastrow = .range("a" & .rows.count).end(xlup).row 'last row data in sheet set rng = .range("a1:a" & lastrow) 'range filter set rngwh = .range("a2:a" & lastrow) 'range formulas lastcol = .cells(1, .columns.count).end(xltoleft).column + 2 'column display data rng.advancedfilter action:=xlfiltercopy, copytorange:=.cells(1, lastcol), unique:=true currlr = .cells(.rows.count, lastcol).end(xlup).row 'unique nr. doc count lastcol = lastcol + 1 'formula base .cells(1, lastcol).value = "base" .range(.cells(2, lastcol), .cells(currlr, lastcol)).formula = _ "=sumproduct((" & .cells(2, lastcol - 1).address(false, false) & "=" & rngwh.address & ")*(left(" & rngwh.offset(, 1).address & ")={""6"",""7""})*(" & rngwh.offset(, 2).address & "))" 'formula vat .cells(1, lastcol + 1).value = "vat" 'enter formula here vat 'formula total .cells(1, lastcol + 2).value = "total" .range(.cells(2, lastcol + 2), .cells(currlr, lastcol + 2)).formula = _ "=sumif(" & rngwh.address & "," & .cells(2, lastcol - 1).address(false, false) & "," & rngwh.offset(, 3).address & ")" .range(.cells(2, lastcol), .cells(currlr, lastcol + 2)).value = .range(.cells(2, lastcol), .cells(currlr, lastcol + 2)).value end application.screenupdating = true application.calculation = xlcalculationautomatic end sub 

Comments
Post a Comment