Move rows on condition and count

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591
Hello everyone,
WIll try to explain this as best as I can
Starting at A1
Row 1 is conditional row for the code
John22
Apple
John
AppleMark
CupJohn
CupMark
AppleSteve
PenMark
etcetc
etcetc
etcetc

<tbody>
</tbody>
What I wish for is in other sheet rows from column A to be moved (not copied) by matching criteria from cell A1, added in column B value from B1, in Column C total counts moved of items in column A matching value in C

So lets say top table has been added twice to the sheet with same criteria
Starting at a1
Apple222
Cup222

<tbody>
</tbody>

If after that criteria changes to ex.
Mark and 22
and
Steve and 40
Apple223
Cup223
Pen221
Apple401

<tbody>
</tbody>

And in next rows all new moved values would be filled

I hope I didn't miss anything and it's all clear :)

Thank you
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
So I came up (with the help of google) with this code which does almost everything I need. It adds new entries, count total add.. but it makes infinitive range as new entries are added to it and looking for total count is not easy to find (its always at the bottom, while some less used entries are lost in the middle). Was trying to fix that but can't. What basicaly I need is all unique values to be listed with total count next to them. And to be updated as new entries are added. Hope it makes sense. Thank you
Code:
Sub week()application.screenupdating = false
dim copysh as worksheet
dim pastesh as worksheet
dim fr as long
dim fr as long
set copysh = worksheets("sheet1")
set pastesh = worksheets("sheet2")
copysh.range("a1:b7").copy
fr = pastesh.cells(cells.rows.<wbr>count,1).end(xlup).row+1
[FONT=sans-serif]pastesh.cells(cells.rows.<wbr>count,1).end(xlup).offset(1,0)<wbr>.pastespecial xlpastevalues[/FONT]
[FONT=sans-serif]lr = pastesh.cells(cells.rows.<wbr>count,1).end(xlup).row[/FONT]
[FONT=sans-serif]pastesh.select[/FONT]
pastesh.range("[FONT=sans-serif]c2:,"c" & lr).value=1[/FONT]
pastesh.range("d" & fr,"d" & lr).formula= "=sumproduct(($a$2:$a$"& lr &"=a"& fr &")*($b$2:$b$"& lr &"=b"& fr &")*($c$2:$c$"& lr &"))"

pastesh.range("a2","d"& lr).copy
pastesh.range("a2").<wbr>pastespecial xlpastevalues
pastesh.range("d2","d"& lr).copy

pastesh.range("c2").<wbr>pastespecial xlpastevalues

application.cutcopymode = false
application.screenupdating = true
copysh.select
end sub
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,265
Members
449,219
Latest member
daynle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top