Empty Rows

vijay2482

Board Regular
Joined
Mar 3, 2009
Messages
142
hi all,

how to move the empty rows to the last filled rows in excel using macros?

thanks in advance
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Possible use sort? Data > Sort > Ascending

You could use the recorder if you want the VBA. Otherwise give us sheet name and ranges that apply and perhaps we can provide the code.
 
Upvote 0
i want to sort this data in order using VBA

i cannot find the attachetment option in my post reply page.
how to attach the file?
thanks for ur response
 
Upvote 0
Well, you have mentioned that there are some empty row,,,,is the whole row empty…there is no data in any column in that row?....if that is so you can delete that unnecessary row with vba code by scanning through the whole sheet as below
Rich (BB code):
Rich (BB code):
Rich (BB code):
Sub Del_Empty()
Dim row As Integer, col As Integer
row = 1
col = 1
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
'suppose you have 100 rows with data in the sheet
<o:p> </o:p>
For row = 1 To 100
    'delete the row if there is no data in the first column
    If Sheet1.Cells(row, col).Value = "" Then
        Sheet1.Rows(row).Delete
    End If
Next
<o:p> </o:p>
End Sub

<o:p> </o:p>
Hope this helps….
 
Upvote 0
i want to delete the row which have no values from column 3

i changed the code as follows:
Code:
 Dim row As Integer, col As Integer
row = 1
col = 3
'suppose you have 100 rows with data in the sheet
For row = 1 To 100
    'delete the row if there is no data in the first column
    If ecn.Cells(row, col).Value = "" Then
        ecn.Rows(row).Delete
    End If
Next

but i find that the rows with values in columns 4,5,6 and 8 are all deleted

and more over i dont want to delete the rows, i want to push the entered rows up and empty rows to the last entered row.

the second column contains the line number, i dont want the line number to be changed when the empty rows are push down
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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