Need VBA help Cut and paste in to another locations if data and condition matches.

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000</SPAN></SPAN>
Hi,</SPAN></SPAN>

It is bit difficult to explain in the brief; so far here I will explain my requirement in the 4 steps to make it easer to understand, sorry for the trouble.</SPAN></SPAN>

Step1</SPAN></SPAN>
This is how looks my data sheet in the columns C, D, E and F, I got 41 data rows and in the columns I, J, K and I got 24 result rows</SPAN></SPAN>
In the G8 I have "SUMPRODUCT formula" copied down to G48, which is checking only I4:L4 result with each row of the columns C, D, E and F,</SPAN></SPAN>
In the G1 there are count for 3 matches and in the G2 there are count for 4 matches sum for both matches are shown in the cell G4</SPAN></SPAN>
Step-1 sheet</SPAN></SPAN>
ABCDEFGHIJKLMNOPQRST
1Step-1Match38
2Match41
3
4Sum9
5
6
7Line nºP1P2P3P4MatchesP1P2P3P4Line nºP1P2P3P4
81111141111
92111X3111X
103111231112
11411X1311X1
12511XX211XX
13611X2211X2
147112131121
158112X2112X
169112221XXX
17101X1131XX1
18111X1X2X112
19121X122X122
20131XX12XX12
21141XXX1XXX1
22151XX21XX2X
23161X212XX22
24171X2X1X2XX
25181X221X2X2
261912113X221
2720121X2X22X
282112122X222
292212X122111
302312XX1211X
312412X212112
322512212
332612221
3427X1113
3528X11X2
3629XX121
3730XXX11
3831XXXX0
3932XXX20
4033X2220
413421113
4235211X2
43362X121
44372XX11
45382XXX0
46392XX20
47402X2X0
48412X220
49

<COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0"><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
Step-1

Worksheet Formulas
CellFormula
G1=COUNTIF(G8:G48,F1)
G2=COUNTIF(G8:G48,F2)
G4=SUM(G1:G2)
G8=SUMPRODUCT(--($I$8:$L$8=C8:F8))

<THEAD>
</THEAD><TBODY>
</TBODY>

<TBODY>
</TBODY>



Step-2</SPAN></SPAN>
Here I want a VBA that can check all the result (of course changing the row numbers of the I:J columns in the G8 SUMPRODUCT formula) "one by one with each of the row are find in the columns C, D, E and F" and if the Sum of cell G4 is = 9 than filter the match greeter than 2 in the column G and cut them from column B, C, D, E and F" and paste in to the columns N:R as shown sheet below </SPAN></SPAN>
Step-2 sheet</SPAN></SPAN>
ABCDEFGHIJKLMNOPQRST
1Step-2Match30
2Match40
3
4Sum0
5
6
7Line nºP1P2P3P4MatchesP1P2P3P4Line nºP1P2P3P4
80111111111
90111X2111X
100111231112
11011X1411X1
12511XX211XX71121
13611X2211X2101X11
1401121191211
158112X2112X27X111
169112221XXX342111
1701XX1
18111X1X2X112
19121X122X122
20131XX12XX12
21141XXX1XXX1
22151XX21XX2X
23161X212XX22
24171X2X1X2XX
25181X221X2X2
260X221
2720121X2X22X
282112122X222
292212X122111
302312XX1211X
312412X212112
322512212
332612221
340
3528X11X2
3629XX121
3730XXX11
3831XXXX0
3932XXX20
4033X2220
410
4235211X2
43362X121
44372XX11
45382XXX0
46392XX20
47402X2X0
48412X220
49

<COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0"><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
Step-2

Worksheet Formulas
CellFormula
G1=COUNTIF(G8:G48,3)
G2=COUNTIF(G8:G48,4)
G4=SUM(G1:G2)
G8=SUMPRODUCT(--($I$8:$L$8=C8:F8))

<THEAD>
</THEAD><TBODY>
</TBODY>

<TBODY>
</TBODY>



Step-3</SPAN></SPAN>
Checking the next matches it has found with G4 Sum = 9 with the row I16:L16 filter greeter than 2 in the column G and cut them from column B, C, D, E and F" and paste in to the columns N:R below the first match as shown sheet below </SPAN></SPAN>
Step-3 sheet</SPAN></SPAN>
ABCDEFGHIJKLMNOPQRST
1Step-3Match38
2Match41
3
4Sum9
5
6
7Line nºP1P2P3P4MatchesP1P2P3P4Line nºP1P2P3P4
80111111111
90111X2111X
100111231112
11011X1411X1
12511XX311XX71121
13611X2211X2101X11
1401121191211
158112X2112X27X111
169112211XXX342111
1701XX1
18111X1X3X112
19121X122X122
20131XX13XX12
21141XXX4XXX1
22151XX23XX2X
23161X212XX22
24171X2X3X2XX
25181X222X2X2
260X221
2720121X2X22X
282112121X222
292212X122111
302312XX3211X
312412X222112
322512211
332612221
340
3528X11X1
3629XX121
3730XXX12
3831XXXX3
3932XXX22
4033X2220
410
4235211X1
43362X121
44372XX12
45382XXX3
46392XX22
47402X2X2
48412X221
49

<COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0"><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
Step-3

Worksheet Formulas
CellFormula
G1=COUNTIF(G8:G48,3)
G2=COUNTIF(G8:G48,4)
G4=SUM(G1:G2)
G8=SUMPRODUCT(--($I$16:$L$16=C8:F8))

<THEAD>
</THEAD><TBODY>
</TBODY>

<TBODY>
</TBODY>



Step-4</SPAN></SPAN>
Here is the final sheet find 2 match only within whole data with sum of 9 in the cell G4</SPAN></SPAN>
Step-4 Sheet

Book1
ABCDEFGHIJKLMNOPQRST
1Step-4Match30
2Match40
3
4Sum0
5
6
7Line nP1P2P3P4MatchesP1P2P3P4Line nP1P2P3P4
80111111111
90111X2111X
100111231112
11011X1411X1
12011XX71121
13611X2211X2101X11
1401121191211
158112X2112X27X111
169112211XXX342111
1701XX1
180X112511XX
19121X122X122111X1X
200XX12131XX1
210XXX1141XXX
220XX2X151XX2
23161X212XX22171X2X
240X2XX2312XX
25181X222X2X231XXXX
260X221382XXX
2720121X2X22X
282112121X222
292212X122111
300211X
312412X222112
322512211
332612221
340
3528X11X1
3629XX121
3730XXX12
380
3932XXX22
4033X2220
410
4235211X1
43362X121
44372XX12
450
46392XX22
47402X2X2
48412X221
49
Step-4
Cell Formulas
RangeFormula
G1=COUNTIF(G8:G48,3)
G2=COUNTIF(G8:G48,4)
G4=SUM(G1:G2)
G8=SUMPRODUCT(--($I$16:$L$16=C8:F8))



I believe it is explained and understand also it is not an easy task hope some one please can take a look and provide a VBA solution </SPAN></SPAN>

Thank you in advance</SPAN></SPAN>

Regards,</SPAN>
Kishan</SPAN></SPAN>
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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