edit the program to sumif with visible cells in MS excel -


i got countifv thats counts visible , sumifsv sum visible cells ... want sumif visible using vba

default using sumifs on visible lines only

i have large table, lots of rows , lots of columns has material (sand, stone, etc.) batched information. wanted able allow user use filters select data want view, able review summary information (totals hour of day, totals material, etc.) on other sheets.

i had working , fast using dsum and/or subtotal, these functions don't exclude non-visible (filtered) lines in list.

using previous posts saw on site, able come works, extremely slow.

i hoping more experienced folks advise me on faster.

what need take list of records on sheet contain 30 material columns of information (target , actual batch weight amounts.) need group each of these lines material relative time bucket (12:00 12:59 am, 1:00 1:59 am, etc.) user can of course select time bucket want view

i using sumifs function 2 critieria ( i.e. time >=12:00 , time < 1:00 ) hourly buckets.

    can see code have count number of lines data , each criteria value because not figure out how set range of "b" & "c" without counting. since using filter, know ranges (from row perspective) of a,b & c same, relative columns different. tried use offset function, (i.e. range(b) = range(a).offset(-1,0).select or b = a.offset(-1,0).select failed reason, , no error messages either. think somehow turned erroring off. 

anyway, long story, use help. here related code:

function vis(rin range) range 'returns subset of rin visible dim cell range 'application.volatile set vis = nothing each cell in rin if not (cell.entirerow.hidden or cell.entirecolumn.hidden) if vis nothing set vis = cell else set vis = union(vis, cell) end if end if next cell end function  function sumifv(rin range, criteriarange1 range, criteriavalue1 variant, criteriarange2 range, criteriavalue2 variant) long 'same excel sumifs worksheet function, except not count 'cells hidden dim a1() range dim b1() range dim c1() range dim csum long ' first count number of ranges cnt = 0 each in vis(rin).areas cnt = cnt + 1 next  redim a1(1 cnt) redim b1(1 cnt) redim c1(1 cnt)  cnta = 1 each in vis(rin).areas set a1(cnta) = cnta = cnta + 1 next cntb = 1 each b in vis(criteriarange1).areas set b1(cntb) = b cntb = cntb + 1 next b cntc = 1 each c in vis(criteriarange2).areas set c1(cntc) = c cntc = cntc + 1 next c  if cnta <> cntb or cntb <> cntc msgbox ("error in sumifs function: counts ranges not same") end if csum = 0 cnt = 1 cnta - 1 csum = csum + worksheetfunction.sumifs(a1(cnt), b1(cnt), criteriavalue1, c1(cnt), criteriavalue2) next sumifv = csum end function 

((countifv visible cells only

if interested, here more general countif solution, , 1 can apply sum , other functions operate on ranges of cells.

this countifv udf uses worksheet function countif count visible cells only, condition argument works same countif. can use countif:

=countifv(a1:a100,1) 

note uses helper function (vis) returns disjoint range of visible cells in given range. can used other worksheet functions cause them operate on visible cells. example,

=sum(vis(a1:a100)) 

yields sum of visible cells in a1:a100. reason why approach of using vis directly in argument list not work countif countif not accept disjoint range input, whereas sum will.

here's udf code:

function vis(rin range) range 'returns subset of rin visible dim cell range application.volatile set vis = nothing each cell in rin if not (cell.entirerow.hidden or cell.entirecolumn.hidden) if vis nothing set vis = cell else set vis = union(vis, cell) end if end if next cell end function  function countifv(rin range, condition variant) long 'same excel countif worksheet function, except not count 'cells hidden dim range dim csum long csum = 0 each in vis(rin).areas csum = csum + worksheetfunction.countif(a, condition) next countifv = csum end function )) 

this both countif , sumifs visible cells need sumif not sumifs please edit 2nd code , compile , post correct program :)

i don't think correct...

......................................using dsum and/or subtotal, these functions don't exclude non-visible (filtered) lines in list.

the behaviour subtotal different "filtered" , "hidden" rows.

this excel help:

for function_num constants 1 11, subtotal function includes values of rows hidden hide rows command under hide & unhide submenu of format command in cells group on home tab in excel desktop application. use these constants when want subtotal hidden , nonhidden numbers in list. function_num constants 101 111, subtotal function ignores values of rows hidden hide rows command. use these constants when want subtotal nonhidden numbers in list.

the subtotal function ignores rows not included in result of filter, no matter function_num value use.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -