Issue - If Statement with "Is Nothing qualifier"

BratFire

Board Regular
Joined
Aug 2, 2005
Messages
99
Recieve a "Cells Not Found" error on the If Statement. I would like, if when filtered data finds nothing, to do nothing. Instead, when the range is empty I get an error on the If statement

Suggestions appreciated.

Thank you.

Code:
  If Range(Cells(headerRow, 1), Cells(lastRow, lastCol )).SpecialCells(xlCellTypeVisible) Is Nothing Then
    msgbox(" no data to copy") 'Do nothing
  Else
    Range(Cells(headerRow , 1), Cells(lastRow, lastCol )).SpecialCells(xlCellTypeVisible).Copy
    Windows(newBook).Activate
    Range("A" & headerRow ).Select: ActiveSheet.Paste: Range("A" & headerRow).Select
    Application.CutCopyMode = False
  End If
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
try (untested):
Code:
Dim myRng as Range
'On Error Resume Next
Set myrng = Range(Cells(headerRow, 1), Cells(lastRow, lastCol)).SpecialCells(xlCellTypeVisible)
'On Error Goto 0
If myrng Is Nothing Then
  MsgBox (" no data to copy")  'Do nothing
Else
  myrng.Copy
  Windows(newBook).Activate
  Range("A" & headerRow).Select: ActiveSheet.Paste: Range("A" & headerRow).Select
  Application.CutCopyMode = False
End If
You may need to enable both commented-out On Error lines
 
Last edited:
Upvote 0
Maybe like this

Code:
On Error Resume Next
  If Range(Cells(headerRow, 1), Cells(lastRow, lastCol)).SpecialCells(xlCellTypeVisible) Is Nothing Then
    If Err <> 0 Then MsgBox (" no data to copy") 'Do nothing
  Else
    Range(Cells(headerRow, 1), Cells(lastRow, lastCol)).SpecialCells(xlCellTypeVisible).Copy
    Windows(newBook).Activate
    Range("A" & headerRow).Select: ActiveSheet.Paste: Range("A" & headerRow).Select
    Application.CutCopyMode = False
  End If
On Error GoTo 0
 
Upvote 0
Actually, I had.

Code:
Set rng = Range(Cells(headerRow + 1, 1), Cells(lastRow, lastCol + 4)).SpecialCells(xlCellTypeVisible, xlNumber)

tried with both xlNumber and without. Currently that line errors as well and I have it commented out.
 
Upvote 0
Actually, I had.

Code:
Set rng = Range(Cells(headerRow + 1, 1), Cells(lastRow, lastCol + 4)).SpecialCells(xlCellTypeVisible, xlNumber)
tried with both xlNumber and without. Currently that line errors as well and I have it commented out.

It looks looks like you'll need the On Error statements in then.
 
Upvote 0
Maybe like this

Code:
On Error Resume Next

...My code as presented above ...

On Error GoTo 0

Hmm. Kind of crapped out on me when the empty range resulted from the filter. Am I missing something?

I am sometimes leary of On Error commands in the middle of my code afraid that an intended error might not be flagged, or dealt with properly.
 
Upvote 0
Copy/paste the whole code you have now.

To quote myself "Am I missing Something?" Yes, I was. if nothing happened as a result of the IF Statment my active workbook never changed and the code would save and close the workbook I was copying from rather than the workbook I was copying to. I fixed my code, and along with with VoG's suggested code from above, and I am in business.

Thank you all for the assistance.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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