Need a macro that will shift data to empty cells within a range.

olismith89

New Member
Joined
Dec 4, 2014
Messages
12
I have searched for hours and can't find what I'm looking for so hope someone can help me.

I have a table of data (A25:G55) to indicate outstanding orders of a product. They are in order of when each order was placed, so not in any specific numerical order. What I want to be able to do is delete all the orders I have completed and then have a macro button that I can click which shifts all the data (but keeps it in the same order as inputted) up into the top left box (B25). Example below.
ABCDEFG
25X15807590510
267590702520105

If I completed orders 15, 80 and 75, I want to be able to manually delete the cells containing those numbers, leaving 3 blank cells, and then click a button to shift it to the example below.

ABCDEFG
25X90510759070
262520105

The "X" is A25 and is essentially a 'dead cell' that is not in use.

Hope someone can help. Happy to clarify further info if needed.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this
VBA Code:
Sub Rearrange()

Dim cell As Range, rngData As Range
Dim i As Long, j As Long, n As Long
Dim AryData(0 To 217) As Variant, e As Variant

Set rngData = Range("A25", "G55")

n = 0
For i = 25 To 55
    For j = 1 To 7
        If Not Cells(i, j) = 0 Then
            AryData(n) = Cells(i, j)
            n = n + 1
        End If
    Next
Next

n = 0
For Each cell In rngData
    cell = AryData(n)
    n = n + 1
Next

End Sub
 
Upvote 0
Hi there, when trying this, I get the following error message.

Cannot run the macro ''<filename'!macroname'>. The macro may not be available in this workbook or all macros may be disabled.
I know macro's aren't disabled as all other macros work.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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