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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,939
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,438
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,652
Messages
5,549,206
Members
410,905
Latest member
Extjel
Top