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!!
 
So when I tried to use the code again later in the same code when working on different sheets, (I just copied and pasted in and changed the sheet names), it didn't work. They are the exact same format and what not, do I have to clear c or something?
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It's all the selecting and activating, then depending on what is currently selected or activated.

You're best off explicitly naming books and sheets.

Try this
Rich (BB code):
Dim bk1 As Worksheet, bk2 As Worksheet, c As Range

'This is Book/Sheet you are searching for errors
Set bk1 = Workbooks("Book1.xls").Sheets("Sheet1")

'This is the Book/Sheet you are filtering and Copying from
Set bk2 = Workbooks("Book2.xls").Sheets("Sheet1")

For Each c In bk1.Range("A5:A30")
    If IsError(c) Then
        bk2.Range("$A$1:$BY$2432").AutoFilter Field:=75, Criteria1:="="
        bk2.Range("BS1").End(xlDown).Copy
        c.Offset(0, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Exit For
    End If
Next c


And adjust book and sheet names accordingly.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
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