+ Reply to Thread
Results 1 to 3 of 3

comparing values in named ranges

Hybrid View

UltimateNeo comparing values in named... 11-29-2019, 06:00 PM
Joske920 Re: comparing values in named... 11-29-2019, 07:50 PM
mjr veverka Re: comparing values in named... 11-29-2019, 10:48 PM
  1. #1
    Forum Contributor
    Join Date
    01-06-2019
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    209

    comparing values in named ranges

    Hello I have 2 named ranges I want the values in named range 2 to be compared against the values in named range 1 and if they match change the background colour of that cell or highlight the cell in named range 1.

    I have tried various versions of this code below, but have run into errors

    Sub CheckNumbers()
    
        Dim rng1 As Range, rng2 As Range, i As Long, j As Long
        Dim rw As Range
       
        With Sheets("Play")
            Set rng1 = .Range("Namedrange1")
            Set rng2 = .Range("Namedrange2")
           
            'For j = 1 To Sheets("Sheet3").Range("C" & Rows.Count).End(xlUp).Row
             For Each rw In Sheets("play").Range("Namedrange1")
                
                If StrComp(Trim(rng1.Value), Trim(rng2.Value), vbDatabaseCompare) = 0 Then
                    rng1.Interior.Color = RGB(255, 255, 0)
                End If
                Set rng2 = Nothing
            
            Set rng1 = Nothing
            
      Next rw
       End With
    End Sub
    Named range 1 = C3:G34
    Named range 2 = N6:R6 1 row

    Thank you for any help provided

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: comparing values in named ranges

    Hi UltimateNeo,

    hope this helps

    
    Sub CheckNumbers()
    
       Dim rng1 As Range, rng2 As Range
       Dim cel1 As Range, cel2 As Range
       
       With Sheets("Play")
          Set rng1 = .Range("Namedrange1")
          Set rng2 = .Range("Namedrange2")
          
          For Each cel1 In Sheets("play").Range("Namedrange1")
             For Each cel2 In Sheets("play").Range("Namedrange2")
                If StrComp(Trim(cel1.Value), Trim(cel2.Value), vbTextCompare) = 0 Then
                   cel1.Interior.Color = RGB(255, 255, 0)
                End If
             Next cel2
          Next cel1
          Set rng2 = Nothing
          Set rng1 = Nothing
       End With
       
    End Sub
    Grtz

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,245

    Re: comparing values in named ranges

    Try such combination:
        'Color   Red  Green Blue
        '=======================
        'Black   0    0     0
        'Blue    0    0     255
        'Green   0    255   0
        'Cyan    0    255   255
        'Red     255  0     0
        'Magenta 255  0     255
        'Yellow  255  255   0
        'White   255  255   255
    
    Sub CheckKangarooNumbers()
        Dim i%, x%, y%, z%, rng1, rng2
        
        With Sheets("Play")
            rng2 = .Range("Namedrange2").Value
            With .Range("Namedrange1")
                rng1 = .Value
                .ClearFormats
                For i = 1 To UBound(rng2, 2)
                    x = x + 25
                    y = y + 50
                    z = z + 5
                    Application.ReplaceFormat.Interior.Color = RGB(100 + x, 50 + y, 10 + z)
                    .Replace What:=rng2(1, i), Replacement:=rng2(1, i), LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
                Next
            End With
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Use 2 Different Named Cell Ranges To Return Values From 1 Of the Ranges In Formula
    By DESSTRO in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-20-2017, 08:37 PM
  2. Copy values of all named range in wb1 to identically named ranges in wb2
    By JAMIAM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2016, 06:58 PM
  3. comparing two named ranges and if at least one match display a message
    By jwarner000 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-04-2013, 08:01 PM
  4. [SOLVED] Comparing corresponding cells between multiple named ranges
    By srob in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2012, 08:13 AM
  5. Comparing oddly named values between two tables
    By Jimboted in forum Excel General
    Replies: 5
    Last Post: 09-03-2010, 08:10 AM
  6. Comparing two named ranges and placing matches into third range
    By hydrojoe11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2008, 10:14 AM
  7. Comparing Named ranges apologies for the dodgey post below
    By Sam Crump in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-07-2006, 08:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1