VBA if value isn't in a range

melewie

Board Regular
Joined
Nov 21, 2008
Messages
188
Office Version
  1. 365
Platform
  1. Windows
Hi All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I’m having trouble with a piece of code to identify if the value of a cell is a value in a range.<o:p></o:p>

I have a range 'Country_Code_Rng' which contains a list of countries

I want to loop through and identify any contries that are not within this list on a database. something like

Code:
NumRows = Cells(65000, 1).End(xlUp).Row
ColNo = 9
    For RowNo = 1 To NumRows
        If Cells(RowNo, ColNo).Value <> [B][COLOR=red]a value in range Country_Code_Rng[/COLOR] [/B]then
 
            Cells(RowNo, ColNo).EntireRow.Copy
            NewWB.Activate
            Worksheets("Major Space Data").Select
            Cells(65000, 1).End(xlUp).Offset(1, 0).Select
            ActiveSheet.Paste
            wBookExec.Activate
            Sheets("Major Data").Activate
 
        End If
 
    Next RowNo

Any help would be great
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try

Code:
If IsError(Application.Match(Cells(RowNo, ColNo).Value, Range("Country_Code_Rng"), 0)) Then
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,915
Members
449,132
Latest member
Rosie14

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