Cut and paste in VBA

yummy

Board Regular
Joined
Jan 18, 2011
Messages
63
I want to compare values in column H starting to from H3 to column K(starting from K3) and if the values are different, I want to cut all the values in row J and K, below the index, and shift (paste) these values a row below (dont want to insert a whole row just cut and paste) and put a zero in the cell above in column J and K that carried the value preivously (before moving down).
Want to do it for the whole column of H (until there is value in row of H.)

Anybody can help me VB code?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If the following macro does not produce the desired result, try posting a sample of the data before and after the macro.

<font face=Calibri><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> test()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> Cell <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> Rng <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br><br>    <SPAN style="color:#00007F">Set</SPAN> Cell = Range("H3")<br>    <br>    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> Cell <> ""<br>        <SPAN style="color:#00007F">If</SPAN> Cell.Value <> Cell.Offset(, 3).Value <SPAN style="color:#00007F">Then</SPAN><br>             <SPAN style="color:#00007F">Set</SPAN> Rng = Cell.Offset(, 2).Resize(, 2)<br>             Rng.Copy<br>             Rng.Offset(1, 0).Insert shift:=xlDown<br>             Rng.Value = 0<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> Cell = Cell.Offset(1, 0)<br>    <SPAN style="color:#00007F">Loop</SPAN><br>    <br>    Application.CutCopyMode = <SPAN style="color:#00007F">False</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>    <br>    MsgBox "Completed...", vbInformation<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,226,729
Messages
6,192,696
Members
453,747
Latest member
tylerhyatt04

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