ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Control - null rnage (https://www.excelbanter.com/excel-programming/444096-error-control-null-rnage.html)

Tim Childs[_5_]

Error Control - null rnage
 
Hi

What test can be used to stop the following code

Range(.Cells(iFirstDataRow, iTestCol), .Cells(lFinalRow,
iTestCol)).SpecialCells(xlCellTypeFormulas, 7)
erroring when there are no cells identified by the Goto-Special command?

i.e. I sometimes get error 1004 - "no cells were found"

thanks

Tim




James Ravenswood

Error Control - null rnage
 
On Jan 7, 5:03*pm, "Tim Childs" wrote:
Hi

What test can be used to stop the following code

Range(.Cells(iFirstDataRow, iTestCol), .Cells(lFinalRow,
iTestCol)).SpecialCells(xlCellTypeFormulas, 7)
erroring when there are no cells identified by the Goto-Special command?

i.e. I sometimes get error 1004 - "no cells were found"

thanks

Tim


Hi Tim:

You need to trap the error:

Sub marine()
Dim r As Range
On Error Resume Next
Set r = Cells.SpecialCells(xlCellTypeFormulas)
If r Is Nothing Then
MsgBox "r is nothing"
End If
End Sub

Tim Childs[_4_]

Error Control - null rnage
 

"James Ravenswood" wrote in message
...
On Jan 7, 5:03 pm, "Tim Childs" wrote:
Hi

What test can be used to stop the following code

Range(.Cells(iFirstDataRow, iTestCol), .Cells(lFinalRow,
iTestCol)).SpecialCells(xlCellTypeFormulas, 7)
erroring when there are no cells identified by the Goto-Special command?

i.e. I sometimes get error 1004 - "no cells were found"

thanks

Tim


Hi Tim:

You need to trap the error:

Sub marine()
Dim r As Range
On Error Resume Next
Set r = Cells.SpecialCells(xlCellTypeFormulas)
If r Is Nothing Then
MsgBox "r is nothing"
End If
End Sub


Tim Childs[_4_]

Error Control - null rnage
 
Hi James

Many thanks for that solution

bw

Tim

"James Ravenswood" wrote in message
...
On Jan 7, 5:03 pm, "Tim Childs" wrote:
Hi

What test can be used to stop the following code

Range(.Cells(iFirstDataRow, iTestCol), .Cells(lFinalRow,
iTestCol)).SpecialCells(xlCellTypeFormulas, 7)
erroring when there are no cells identified by the Goto-Special command?

i.e. I sometimes get error 1004 - "no cells were found"

thanks

Tim


Hi Tim:

You need to trap the error:

Sub marine()
Dim r As Range
On Error Resume Next
Set r = Cells.SpecialCells(xlCellTypeFormulas)
If r Is Nothing Then
MsgBox "r is nothing"
End If
End Sub



All times are GMT +1. The time now is 03:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com