VBA to move rows of data up removing blank rows.

dbmathis

Well-known Member
Joined
Sep 22, 2002
Messages
1,064
Hi all,

I have the following senario.
Transaction Register Starting Dec-16-2005 Draft.xls
KLMN
10DesciprionAmount
11#121 Tags$177.640
12#123 Truck$279.890
13#122 Emmy's Car$280.000
140
150
16Burger King$6.900
170
180
190
200
210
220
230
24St.Albert$5.000
25HEB$49.060
260
270
280
290
300
310
Transaction Register


Due to the limitations of space on this forum I am only showing K11:M31 but my actual sheet has an area of K11:M41.

Does anyone know how to do the following with VBA? Basically move all blank lines to the bottom of the K11:M41 and move all rows that contain data to the top of the area?

The location of the rows of data within the area of K11:K41 varies from day to day depending on what's deleted, which is what creates these blank lines between data.

For example the end result would be:
Transaction Register Starting Dec-16-2005 Draft.xls
KLMN
10DesciprionAmount
11#121 Tags$177.640
12#123 Truck$279.890
13#122 Emmy's Car$280.000
14Burger King$6.900
15St.Albert$5.000
16HEB$49.060
170
180
Transaction Register


Thanks.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Thanks everyone on this forum who have helped me over the years. Especially Norie, Jindon, Erik, and Gibbs.

Because of your code that I have studied, I can go back through my posts and solve problems that others have previously provided me solutions for such as this thread.

I just wanted you all to know that not all of us take your code and run. Some of us actually learn from your examples.

This code took me 2 minutes to write. Thanks everyone for teaching us code virgins how it's done.

My solution:

Code:
Sub test()
Dim y, z

y = Range("h10:j30"): iii = 1
ReDim z(1 To UBound(y, 1), 1 To UBound(y, 2))
For i = 1 To UBound(y)
    If Not IsEmpty(y(i, 1)) Then
        For ii = 1 To UBound(y, 2)
            z(iii, ii) = y(i, ii)
        Next
        iii = iii + 1
    End If
Next
Range("h10:j30").ClearContents
For i = 1 To UBound(y, 1)
    For ii = 1 To UBound(y, 2)
        Cells(i + 9, ii + 7) = z(i, ii)
    Next
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,323
Messages
6,124,246
Members
449,149
Latest member
mwdbActuary

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