1004 Error: no cells were found, simple solution?

In my macro, I have a segment that looks at a range, and finds and fills empty cells.

Range("E10:A" & CStr(bottom - 1)).Select Selection.SpecialCells(xlCellTypeBlanks).Select Selection.Value = "N/A" 

Where

 bottom = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row 

This works great when an empty cell is present within the range, but throws "1004 Error: No cells were found." on the line specialcells.select. I am having trouble thinking about how to easily solve this problem.

I understand that I can run a loop through a range to check empty cells first, but I feel that this method will be slow and awkward.

Does anyone have a faster and / or simpler solution?

PS I know that I can consolidate my lines of code above, I just explained it as follows, so that it is easier to understand;

  Range("E10:A" & CStr(bottom - 1)).SpecialCells(xlCellTypeBlanks).Value = "N/A" 
+5
source share
1 answer

What can you do to avoid an error, add an error handler

Example:

 Sub Main() On Error GoTo NoBlanks Range("A1:A10").SpecialCells(xlCellTypeBlanks).Value = "N/A" NoBlanks: Resume Next ' or add code here to execute when there are no empty cells End Sub 
+10
source

Source: https://habr.com/ru/post/1200662/


All Articles