If "#NA" is in Range, Do this

HobbesNYC

New Member
Joined
Aug 8, 2012
Messages
13
Hi All,

I'm trying to make an if. I want it to search a range (N5-N30) and if the value "N/A" is in any cell, to click on that cell, move 8 over, then run the blue code (the blue code already works). Any ideas how to make the If, Then, Search, Offset, Select work?


If ActiveSheet.Range("N5:N30").Value = "#N/A" Then
Selection.Offset(0, 8).Select
Windows(t).Activate ' Activate Book2
ActiveSheet.Range("$A$1:$BY$2432").AutoFilter Field:=75, Criteria1:="="
Columns("BS").Select
Selection.End(xlDown).Select
Selection.Copy
Windows(s).Activate 'Activate Book1
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Else
End If


Thank you!!
 
Can you tell me how to get started with that? I don't know how to use that function and I can't find it online. I'm literally 4 days into using VBA.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try

Rich (BB code):
For Each c In Range("N5:N30")
    If IsError(c) Then
        '....do some stuff

       Exit For
    End if
Next c

Although this will capture ANY error, not just #N/A specifically.
 
Upvote 0
You can avoid looping with
Rich (BB code):
If (Application.Sum(Range"N5:N30") = CVErr(xlErrNa)) Then

Unless there are OTHER errors in the range, AND the first error in the range is something other than #N/A.

Of coarse my code has the same problem..


To specifically look for #N/A, you would have loop and use
Application.ISNA(...) like in post#2

something like
Rich (BB code):
For Each c In Range("A1:A10")
    If Application.IsNA(c) Then
        'Do some stuff

        Exit For
    End If
Next c
 
Last edited:
Upvote 0
So this kinda worked. It searched for the error but it didn't select it. It just pasted into the cell it was already in:

For Each c In Range("A5:A30")
If IsError(c) Then
Selection.Offset(0, 0).Select
'For now, later I will change it to 8 over
Windows(t).Activate ' Activate Book2
ActiveSheet.Range("$A$1:$BY$2432").AutoFilter Field:=75, Criteria1:="="
Columns("BS").Select
Selection.End(xlDown).Select
Selection.Copy
Windows(s).Activate 'Activate Book1
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Exit For
End If
Next c
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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