Move cells in columns according to the Value in Column A

fddekker

Board Regular
Joined
Jun 30, 2008
Messages
86
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that is more than 100's of thousands of rows. In smaller cases, I would simply insert subtotals and then copy and paste visible cells to another sheet to see all the items related to a specific account in one row, but in this case I can't do it. How can I use VBA to check if the amount in a column belongs to an account number in column A that have more than one entry. If the account number has more than one entry, the amount should be moved to the top row of that specific account. All amounts related to an account should thus be in the same row. I am adding a screenshot of the raw data (left) and the expected layout (right).

Any help appreciated.
 

Attachments

  • Allighn Cells.PNG
    Allighn Cells.PNG
    58.2 KB · Views: 11

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
try this on a copy of your file

VBA Code:
Sub do_It()
Application.ScreenUpdating = False
acct = [A2]
sr = 2

For r = 3 To Range("A" & Rows.Count).End(xlUp).Row

If Cells(r, "A") = acct Then
    For c = 3 To 7
        If Cells(r, c) <> "" Then Cells(sr, c) = Cells(r, c)
        Cells(r, c) = ""
        Cells(r, "A") = ""
    Next c
    
Else
    acct = Cells(r, "A")
    sr = r
End If

Next r
Application.ScreenUpdating = True
End Sub

hth,
Ross
 
Upvote 0
Solution
Fantastic!!! Thank you soo much, and with such efficient code!
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,849
Members
449,194
Latest member
HellScout

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