Checking if a Row is empty - CountA not working

jimayers

Board Regular
Joined
Nov 14, 2010
Messages
99
Hello - I am having a lot of trouble trying to get this line to work:
Code:
If WorksheetFunction.CountA(bFind) = 0 Then Goto a:

I have 3 columns and the following code looks for a value "B2" (through "B5") in row(3) and then inserts a blank row on the first instance each is found. It works for the most part, except for the CountA function:
Code:
Sub Insert_Blank_Rows()
Dim Lastrow, bFind As Range
Dim i As Integer


For i = 2 To 5
    Lastrow = Cells(Rows.Count, 3).End(xlUp).Row
    Set bFind = ActiveSheet.Range("C5:" & "C" & Lastrow).Find(What:="B" & i, LookIn:=xlValues, LookAt:=xlPart)
    
    If bFind Is Nothing Then GoTo a:    
    [SIZE=2][B]If WorksheetFunction.CountA(bFind) = 0 Then Goto a:[/B][/SIZE]
       ''''If bFind = "" Then GoTo a: (this doesn't work either)
    bFind.EntireRow.Insert shift:=xlUp  ' inserts row
    Rows(bFind.Row - 1).RowHeight = 9  ' sets row height
a:
Next i
End Sub
I need the code to properly find the empty row so I can insert more code based on the empty row. By inserting message boxes I was able to determine that the code does not work.
Can anybody help?
Thanks for your help - Jim A
 
Yes, the new rows must be empty if no other part of the code is filling them, but are you sure bfind is that range? Test by adding a line like: bfind.interior.colorindex = 5 to highlight.
 
Upvote 0

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

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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