How to Avoid Run Time Error 1004 without using On Error Resume Next

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Hello

I am searching string which is typed in Textbox and returns the Row number an Cell Address of that string.
I've used Special Cells(xlTypeBlanks) because majority of rows in the Range are with 2 or 3 Empty Cells .

Few Rows are NON-EMPTY because of this I get Error 1004 (Blank) Cells Are Not Found

Although Using On Error Resume Next it works Perfectly.

Will there be any possibility Without using On Error Resume Next we can avoid Error 1004


VBA Code:
Private Sub UserForm_Initialize()
    TextBox1.Text = "12345678"
End Sub

Private Sub CmdFindWhichRow_Click()

Dim getRowNo As Range, BlankCells As Range, BlankCellsOfGetRowNo As Range

Set getRowNo = Worksheets("Sheet5").Range("E:E").Find(TextBox1.Text, LookIn:=xlValues, LookAt:=xlWhole)

Set BlankCellsOfGetRowNo = Worksheets("Sheet5").Range("A" & getRowNo.Row & ":J" & getRowNo.Row).SpecialCells(xlCellTypeBlanks)
'The above Gives Run Time Error 1004 as The Row Was full with NON/BLANK (EMPTY) Cells
End Sub

Your valuable inputs shall be appreciated

Thanks
NimishK
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You could use Application.Countblank to test the range first.
 
Upvote 0
Solution
You could use Application.Countblank to test the range first.

Thank you Sir for the Hint

i tried

using following Syntax
VBA Code:
Set BlankCellsOfGetRowNo = Worksheets("Sheet5").Range("A" & getRowNo.Row & ":J" & getRowNo.Row).SpecialCells(xlCellTypeBlanks)

Worksheets("Sheet5").Range("A" & getRowNo.Row & ":J" & getRowNo.Row) = Application.WorksheetFunction.CountBlank(Worksheets("Sheet5").Range("A" & getRowNo.Row & ":J" & getRowNo.Row))
Still I get Error 1004 on line with the wrong syntax i incorporated in.

Will Appreciate if you could help me to correct the syntax

Thanks
NimishK
 
Upvote 0
Wait Sir
Tried the Following
VBA Code:
If Application.WorksheetFunction.CountBlank(Worksheets("Sheet1").Range("A" & getRowNo.Row & ":J" & getRowNo.Row)) = "0" Then
MsgBox "There Are Non Empty Cells"
Else
MsgBox "Blank Cells Found"
End If

So therefore still do i have to use the following and to get rid of below
VBA Code:
Set BlankCellsOfGetRowNo = Worksheets("Sheet5").Range("A" & getRowNo.Row & ":J" & getRowNo.Row).SpecialCells(xlCellTypeBlanks
NimishK
 
Upvote 0
You would only set the range variable if the countblank is not 0.
 
Upvote 0
You would only set the range variable if the countblank is not 0.

Thank you Sir, for your valuable inputs.

This hint and explanation is sufficient enough

Thank you once more

NimishK
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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