Move Numbers in adjacent cells

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
822
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
DebitCredit
IJ
2 75.25
3 75.25
4 1500.88
5 1500.88

<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>
</tbody>



Expected result

DebitCredit
IJ
2 75.25
375.25
4 1500.88
51500.88

<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>
</tbody>
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,938
Office Version
  1. 2019
Platform
  1. Windows
Will the Debits always be in the row directly below the credit?
 

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
822
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!
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,435
Office Version
  1. 2010
Platform
  1. Windows
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
 

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
822
Perfect work Rick! Thank you once again for your continuance support. Hv a lovely day!
 

Watch MrExcel Video

Forum statistics

Threads
1,114,513
Messages
5,548,492
Members
410,840
Latest member
Kar3ousse
Top