Delete row when linked cell values are empty

cdfjdk

New Member
Joined
Sep 3, 2014
Messages
31
I want my macro to loop through a series of files and, if all the cells B10:F10 in Sheet2 are empty, then delete row 10.


I think my problem is that the value in each cell is linked from Sheet1 and the zero for an empty field is hidden (e.g. ='Sheet1'!B22 & ""); I have tried to delete for both Cell.Value = " " and "0" without success.


The loop runs OK. If I set Cell.Value = "", then it deletes row 10 regardless of whether the fields are empty or not.

Guidance very gratefully received!

Code:
Dim found As Boolean


found = False


    Sheets("Sheet2").Select


        For Each cell In Range("B10:F10").Cells
            If cell.Value = " " Then
                found = True
            End If


        Next
        
        If found = True Then
        Rows(10).EntireRow.Delete Shift:=xlUp
        
        End If
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You can try it this way.
Code:
Sub t()
Dim c As Range
With Sheets(2)
    For Each c In .Range("B10:F10")
        If c.Value <> "" And c.Value <> 0 Then
            Exit Sub
        End If
    Next
    .Rows(10).Delete
End With
End Sub
this will test for the value of Empty String or blank. Even if you have a formula that returns the "" value, it will not regard that cell as having value..
 
Upvote 0
Thank you, JLGWhiz - that is very elegant!
I have made one change, because the
Code:
Exit Sub
terminates the loop at the first file in which there is a value in the range. I have replace the
Code:
Exit Sub
with a
Code:
GoTo
that goes to the conclusion of the macro.
 
Upvote 0
Thank you, JLGWhiz - that is very elegant!
I have made one change, because the
Code:
Exit Sub
terminates the loop at the first file in which there is a value in the range. I have replace the
Code:
Exit Sub
with a
Code:
GoTo
that goes to the conclusion of the macro.

Thanks for the feedback,
regards, JLG
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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