excel - How to Count/Merge identical rows of data and add them in a column -
lets have 10,000 rows of data, sample shown below, h1
= header1
.
i'm trying merge identical columns , reflect in last column (header6), ie i'm trying add them up, collapsing repeated rows. however, difficulty i'm facing these (including header6) text not numbers. preferably using excel vba (data must in excel)
h1 h2 h3 h4 h5 h6 aa bb ee hh kk 1* aa cc ee gg kk 1* aa cc ee gg kk 1* aa cc ee gg kk 1* aa dd ff hh kk 1* aa dd ff hh kk 1*
the criteria fields, header1
header5
must identical, , add in header6
. result of scenario should follows:
h1 h2 h3 h4 h5 h6 aa bb ee hh kk 1* aa cc ee gg kk 3* aa dd ff hh kk 2*
i tried many ways no avail. appreciate assistance.
try this:
sub test() dim dic object, cl range, i&, s$, key variant set dic = createobject("scripting.dictionary") dic.comparemode = vbtextcompare = cells(rows.count, "a").end(xlup).row each cl in range("a2:a" & i) s = cl & "|" & _ cl.offset(, 1) & "|" & _ cl.offset(, 2) & "|" & _ cl.offset(, 3) & "|" & _ cl.offset(, 4) & "|" & _ cl.offset(, 5) if not dic.exists(s) dic.add s, 1 else dic(s) = clng(dic(s)) + 1 end if next cl worksheets.add = 2 [a1:f1].value = split("h1|h2|h3|h4|h5|h6", "|") each key in dic range(cells(i, "a"), cells(i, "e")).value = split(key, "|") cells(i, "f") = dic(key) = + 1 next key end sub
source
destination
Comments
Post a Comment