Finding empty cells in a Row and doing something when found

jimayers

Board Regular
Joined
Nov 14, 2010
Messages
99
Hello - i would appreciate some help with finding empty cells in a row and then doing something when found. My code for testing is:
Code:
Sub TEST_Find_EmptyRows_DeleteRow()
Application.ScreenUpdating = False
Dim r as Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For r = 1 To Lastrow
    If Range(Cells(r, 1) & ":" & Cells(r, 26)) Is Empty Then Rows(r).Interior.ColorIndex = 5  '.Delete
   
    
Next r
Application.ScreenUpdating = True
End Sub

Thank you for all your help - Jim A
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this
Code:
For r = 1 To Lastrow
    If Application.CountA(Range(Cells(r, 1) & ":" & Cells(r, 26)) = 0 Then Rows(r).Interior.ColorIndex = 5  '.Delete    
Next r
The CountA function will check for any data, including formulas that may exist in the target range.

The IsEmpty function in VBA is primarily used to determine if variables have been initialized, and not to test for data in cells. It will give you false readings if used to test cells for data content. You can test a single cell to equal an empty string ("") or if working with numerical data on a range of cells, you can use
If Application.Sum(<enter range here>) = 0
. And a couple of other ways to check if values are entered or not, but I would not use IsEmpty.
 
Last edited:
Upvote 0
Try this
Code:
For r = 1 To Lastrow
    If Application.CountA(Range(Cells(r, 1) & ":" & Cells(r, 26)) = 0 Then Rows(r).Interior.ColorIndex = 5  '.Delete    
Next r
The CountA function will check for any data, including formulas that may exist in the target range.

The IsEmpty function in VBA is primarily used to determine if variables have been initialized, and not to test for data in cells. It will give you false readings if used to test cells for data content. You can test a single cell to equal an empty string ("") or if working with numerical data on a range of cells, you can use . And a couple of other ways to check if values are entered or not, but I would not use IsEmpty.

Thanks for the details and help - extremely helpful.

Thanks - Jim A
 
Upvote 0

Forum statistics

Threads
1,215,205
Messages
6,123,634
Members
449,109
Latest member
Sebas8956

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