How to delete empty rows starting from a certain column

occitan

New Member
Joined
Nov 15, 2017
Messages
15
Hello everybody!

I have a dataset in excel containing 25684 rows and 1868 columns.

The first 6 columns all contain name identifiers for all the rows (hence, there are no empty cells in the rows for the first 6 columns). However, from column 7 onwards, since there are numerical values, many rows have missing observations. So there are rows which always contain values from column 1-6, but after column 6 they have all empty values. I want to eliminate all these rows.

I was trying to set up a Macro through VBA which deleted rows having empty cells but WITHOUT considering the first 6 columns.

I tried this, but it doesn't work (It doesn't take consider the range I want for the elimination):


SubBlank_Rows()
Dim i As Long, LastRow as Long

SetmyRange = ActiveSheet.Range("G2:BSV25684")
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = Lastrow To 1 Step -1
If WorksheetFunction.CountA(Rows(i)) = 0 Then
Rows(i).EntireRow.Delete
End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub


Does someone know how to solve this?

Thank you very much!

O.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi & welcome to the board.
Try
Code:
If WorksheetFunction.CountA(Range("G" & i).Resize(, 1862)) = 0 Then
 
Upvote 0
This deletes the entire row with out any regard to any selected range.
Code:
[COLOR=#000000][FONT=&quot]Rows(i).EntireRow.Delete[/FONT][/COLOR]


Does this do what you want?
Code:
Sub Blank_Rows()

Dim i As Long, LastRow As Long, lc As Long


With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False


LastRow = Cells(Rows.Count, "A").End(xlUp).Row




For i = LastRow To 1 Step -1
    lc = Cells(i, Columns.Count).End(xlToLeft).Column
    If lc = 6 Then
        Range("G" & i & ":BSV" & i).Delete shift:=xlShiftUp
    End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
 
Upvote 0
Thank you Fluff and Scott!

Many thanks Scott! That was exaclty the code I was looking for!

You made my day! :) Thanks! ^_^

O
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,532
Members
449,169
Latest member
mm424

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