Move Numbers in adjacent cells

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
890
Hi all, Kindly advice me for a VBA code so that to move the duplicate numbers from credit side which is col. "J" to col "I". Note that the code should move the second number. I present below an extract of original data and expected result. Thank you all in advance

Original data

<colgroup><col style="mso-width-source:userset;mso-width-alt:995;width:21pt" width="28"> <col style="mso-width-source:userset;mso-width-alt:2531;width:53pt" width="71"> <col style="mso-width-source:userset;mso-width-alt:2531;width:53pt" width="71"> </colgroup><tbody>
[TD="class: xl63, width: 28"] [/TD]
[TD="class: xl63, width: 71"]Debit[/TD]
[TD="class: xl66, width: 71"]Credit[/TD]

[TD="class: xl63, width: 28"] [/TD]
[TD="class: xl69, width: 71"]I[/TD]
[TD="class: xl70, width: 71"]J[/TD]

[TD="class: xl65, width: 28"]2[/TD]
[TD="class: xl64, width: 71"] [/TD]
[TD="class: xl67, width: 71"]75.25[/TD]

[TD="class: xl65, width: 28"]3[/TD]
[TD="class: xl64, width: 71"] [/TD]
[TD="class: xl67, width: 71"]75.25
[/TD]

[TD="class: xl65, width: 28"]4[/TD]
[TD="class: xl64, width: 71"] [/TD]
[TD="class: xl67, width: 71"]1500.88[/TD]

[TD="class: xl65, width: 28"]5[/TD]
[TD="class: xl64, width: 71"] [/TD]
[TD="class: xl67, width: 71"]1500.88[/TD]

</tbody>



Expected result


<colgroup><col style="mso-width-source:userset;mso-width-alt:995;width:21pt" width="28"> <col style="mso-width-source:userset;mso-width-alt:2531;width:53pt" width="71"> <col style="mso-width-source:userset;mso-width-alt:2531;width:53pt" width="71"> </colgroup><tbody>
[TD="class: xl66, width: 28"] [/TD]
[TD="class: xl67, width: 71"]Debit[/TD]
[TD="class: xl68, width: 71"]Credit[/TD]

[TD="class: xl67, width: 28"] [/TD]
[TD="class: xl71, width: 71"]I[/TD]
[TD="class: xl72, width: 71"]J[/TD]

[TD="class: xl66, width: 28"]2[/TD]
[TD="class: xl65, width: 71"] [/TD]
[TD="class: xl69, width: 71"]75.25[/TD]

[TD="class: xl66, width: 28"]3[/TD]
[TD="class: xl65, width: 71"]75.25[/TD]
[TD="class: xl69, width: 71"] [/TD]

[TD="class: xl66, width: 28"]4[/TD]
[TD="class: xl65, width: 71"] [/TD]
[TD="class: xl69, width: 71"]1500.88[/TD]

[TD="class: xl66, width: 28"]5[/TD]
[TD="class: xl65, width: 71"]1500.88[/TD]
[TD="class: xl69, width: 71"] [/TD]

</tbody>
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Will the Debits always be in the row directly below the credit?
 
Upvote 0
Yeap alan, therefore that the original data are always below credit side and i would like to move each second number in debit side col. "I". Apologies for my faulty presentation. The first row is headings (Debit and Credit) in col. "I" and "J" respectively. Thank you for your respond. Hv a great day!
 
Upvote 0
Give this macro a try...
Code:
Sub MoveDuplicateNumbers()
  Dim R As Long
  For R = 2 To Cells(Rows.Count, "J").End(xlUp).Row
    If Cells(R, "J").Value = Cells(R - 1, "J").Value Then Cells(R, "J").Cut Cells(R, "I")
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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