VBA - determine if a cell value (String) matches a Value (String) in a named range

Jb86

apologies if this has already been answered although I have searched and search with no luck. in a nutshell im trying to change the cell colour if that cell value does not match a value in a named range.

I have tried a number of methods although none are working for me , any help from the vba gurus would be greatly appreciated.

essentially I have a list of values on sheet1(Create) G2:G5000 that I need to know when they don't match value on sheet2(lists) S2:S64 <--this has a named range of Make.

please see a copy of my current code below


Sub testMake()

    Dim MkData As Range, MkVal As Range
    Dim MKArray As Variant

    Set MkData = Worksheets("Create").Range("G2:G5000")
    Set MkVal = Worksheets("Lists").Range("Make")

    For Each MyCell In MkData
        If MyCell.Value <> Range("MkVal") Then
            MyCell.Interior.ColorIndex = 6
        Else
            MyCell.Interior.ColorIndex = xlNone
        End If

    Next


End Sub

Thanks you all for any help in advance, I have been looking at this for a few days now and seem to be no closer than when I started.

Shai Rado

You could be using Worksheet function Vlookup to compare between the two ranges:

Sub testMake()

Dim MkData As Range, MkVal As Range
Dim MKArray As Variant
Dim result  As Variant

Set MkData = Worksheets("Create").Range("G2:G5000")
Set MkVal = Worksheets("Lists").Range("Make")

For Each MyCell In MkData
    On Error Resume Next
    result = Application.WorksheetFunction.VLookup(MyCell, MkVal, 1, False)

    If Err <> 0 Then
        result = CVErr(xlErrNA)
    End If

    If Not IsError(result) Then
        MyCell.Interior.ColorIndex = xlNone
    Else
        MyCell.Interior.ColorIndex = 6
    End If
Next

End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

VBA - determine if a cell value (String) matches a Value (String) in a named range

From Dev

How can I use a Cell Value as a Named Range in VBA?

From Dev

Read range value from a STRING cell

From Dev

Read range value from a STRING cell

From Dev

MS Excel VBA find cell with string value

From Dev

Excel Vba getting value of cell and setting a string

From Dev

Remove value in one cell from string in another cell (VBA)

From Dev

Refer to Named Range from Cell Value in For Loop

From Dev

Dynamic Named Range based on Another Cell Value

From Dev

String that changes with cell value?

From Dev

Set a string to a value in a cell?

From Dev

access value (content) of a named cell in Excel VBA

From Dev

Getting a value from a named range in VBA

From Dev

Return True or False if value in cell matches value in range of cells

From Dev

Search a range for a string- check if string of the cell beside matches

From Dev

google sheets if string matches and is last matching string in set of cells get value of cell nest to it

From Dev

Excel VBA find a cell on worksheet with specific value (string)

From Dev

In a subset of cells, determine if at least one corresponding cell matches a value

From Dev

Excel VBA to select a range based on cell value

From Dev

Excel VBA function to lookup value in a Cell range

From Dev

Excel VBA: Color range based on cell value

From Dev

Excel VBA function to lookup value in a Cell range

From Dev

Split string in array not in cell range vba

From Dev

Is it possible to match a string $x = "foo" with a variable named $foo and assign a value only if it matches?

From Dev

Find a cell in a table or range, if the cell matches it then it returns the value next to the cell in the range

From Dev

Export to PDF with String and Cell Value

From Dev

Formula to match/lookup if part of a string in a cell is equal to a value in a given range and return this value

From Dev

VBA - CountIf cell range displayed value is equal to desired value

From Dev

Pass a string value to a range object

Related Related

  1. 1

    VBA - determine if a cell value (String) matches a Value (String) in a named range

  2. 2

    How can I use a Cell Value as a Named Range in VBA?

  3. 3

    Read range value from a STRING cell

  4. 4

    Read range value from a STRING cell

  5. 5

    MS Excel VBA find cell with string value

  6. 6

    Excel Vba getting value of cell and setting a string

  7. 7

    Remove value in one cell from string in another cell (VBA)

  8. 8

    Refer to Named Range from Cell Value in For Loop

  9. 9

    Dynamic Named Range based on Another Cell Value

  10. 10

    String that changes with cell value?

  11. 11

    Set a string to a value in a cell?

  12. 12

    access value (content) of a named cell in Excel VBA

  13. 13

    Getting a value from a named range in VBA

  14. 14

    Return True or False if value in cell matches value in range of cells

  15. 15

    Search a range for a string- check if string of the cell beside matches

  16. 16

    google sheets if string matches and is last matching string in set of cells get value of cell nest to it

  17. 17

    Excel VBA find a cell on worksheet with specific value (string)

  18. 18

    In a subset of cells, determine if at least one corresponding cell matches a value

  19. 19

    Excel VBA to select a range based on cell value

  20. 20

    Excel VBA function to lookup value in a Cell range

  21. 21

    Excel VBA: Color range based on cell value

  22. 22

    Excel VBA function to lookup value in a Cell range

  23. 23

    Split string in array not in cell range vba

  24. 24

    Is it possible to match a string $x = "foo" with a variable named $foo and assign a value only if it matches?

  25. 25

    Find a cell in a table or range, if the cell matches it then it returns the value next to the cell in the range

  26. 26

    Export to PDF with String and Cell Value

  27. 27

    Formula to match/lookup if part of a string in a cell is equal to a value in a given range and return this value

  28. 28

    VBA - CountIf cell range displayed value is equal to desired value

  29. 29

    Pass a string value to a range object

HotTag

Archive