macro row delete help

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
hi all. i have a spreadsheet sheet that has possible values in the range H7:N21

I want to delete an entire row if that row does not have a value in the range between H:N

i beleive this is a loop inside a loop but i think i am way over complicating things. here is my loops i have now:

Code:
 For i = 7 To 21
    With Range("H" & i)
        If .Value = "" Then
            For c = 9 To 14
                With Range(c & i)
                    If .Value = "" Then
                        Next c
                    Else
                        Next i
                    End If
                End With
       Else
        Next i
   End With

hope someone can assist.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try

Code:
For i = 21 To 7 Step - 1
    With Range("H" & i)
        If WorksheetFunction.CountA(.Resize(, 7).Value) = 0 Then Rows(i).Delete
    End With
Next i
 
Upvote 0
Plost, your original macro doesn't seem to have a row delete command anywhere in it - you just tell it whether to move to the next row or next column, but you don't tell it what to do in the case that it gets to the end of a row having found no values.
 
Upvote 0
yes i know that. i need to add that in...as it is currently i am getting an error saying i dont have a "next" for the "c" ...so i did not add that in yet. i think i am making it a bit to difficult...
 
Upvote 0
Here's a really bad version of the macro that will work:

Range("H7").Select
del = 0
For r = 7 To 21
For c = 1 To 8
If ActiveCell.Value <> "" Then
del = 1
End If
ActiveCell.Offset(0, 1).Select
Next c
If del = 0 Then
ActiveCell.EntireRow.Delete
ActiveCell.Offset(0, -8).Select
Else
ActiveCell.Offset(1, -8).Select
End If
del = 0
Next r
 
Upvote 0
does anyone know a better way to do this?

I want to delete the entire row if none of the cells on that row have value in between column H and N.

this should apply to rows 7 through 21



hope someone can help.
 
Upvote 0
does anyone know a better way to do this?

I want to delete the entire row if none of the cells on that row have value in between column H and N.

this should apply to rows 7 through 21



hope someone can help.

The macro I posted will do just what you ask - it's inelegant, but it works.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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