Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Comparing 2 dynamic ranges for matching names


I've spent the last 5-6 hours trying to solve this problem with no joy

I have one named range called Highlighted_names


Code:
--------------------
=OFFSET(Highlighted_data!$A$3,0,0,COUNTA(Highlight ed_data!$A:$A),1)
--------------------


and another called Downloaded_list


Code:
--------------------
=OFFSET(Download_sheet!$B$2,0,0,COUNTA(Download_sh eet!$B:$B),1)
--------------------


These are on 2 different sheets.

My hope is have a Marco that checks the cells in the first range and
compares it to the second range and Selects any matches.

I then intend to highlight the rows in which these matches occur.

Any help would be appreciated


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=473778

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing 2 dynamic ranges for matching names

Dim rng1 as Range, rng2 as Range
Dim res as Variant, cell as Range
set rng1 = Range("Highlighted_Names")
set rng2 = Range("DownLoadedList")
rng1.Interior.colorIndex = xlNone
for each cell in rng1
res = Application.Match(cell,rng2,0)
if not iserror(res) then
cell.Interior.colorIndex = 3
end if
Next


--
Regards,
Tom Ogilvy

"Daminc" wrote in
message ...

I've spent the last 5-6 hours trying to solve this problem with no joy

I have one named range called Highlighted_names


Code:
--------------------
=OFFSET(Highlighted_data!$A$3,0,0,COUNTA(Highlight ed_data!$A:$A),1)
--------------------


and another called Downloaded_list


Code:
--------------------
=OFFSET(Download_sheet!$B$2,0,0,COUNTA(Download_sh eet!$B:$B),1)
--------------------


These are on 2 different sheets.

My hope is have a Marco that checks the cells in the first range and
compares it to the second range and Selects any matches.

I then intend to highlight the rows in which these matches occur.

Any help would be appreciated


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:

http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=473778



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Comparing 2 dynamic ranges for matching names

Here is an adaptation of some code that I already have. It looks for a match
in two different ranges. It creates a new sheet listing the matched items.
You should be able to adapt this to your needs... For this code to work you
need to reference "Microsoft Scripting Runtime" (in the VB editor Tools -
References...)

Sub Matched()
Dim rngRange1 As Range
Dim rngRange2 As Range
Dim rngCurrent As Range
Dim Dic1 As Scripting.Dictionary 'Dictionary Object
Dim Dic2 As Scripting.Dictionary 'Dictionary Object
Dim varMatched As Variant 'Array of unmatched items
Dim wksNew As Worksheet
Dim lngCounter As Long

Set rngRange1 = Sheets("Sheet1").Range("A1:A100") 'Change This
Set rngRange2 = Sheets("Sheet2").Range("A1:A50") 'Change This

Set Dic1 = CreateDictionary(rngRange1)
Set Dic2 = CreateDictionary(rngRange2)
varMatched = MatchedArray(Dic1, Dic2)
If IsArray(varMatched) Then
Set wksNew = Sheets.Add
With wksNew
.Range("A1").Value = "Matched Items"
Set rngCurrent = .Range("A2")
For lngCounter = LBound(varMatched) To UBound(varMatched)
rngCurrent.Value = varMatched(lngCounter)
Set rngCurrent = rngCurrent.Offset(1, 0)
Next lngCounter

End With
Else
MsgBox "No Matching Items", vbOKOnly, "No Matches"
End If

End Sub

Private Function CreateDictionary(ByVal Target As Range) As
Scripting.Dictionary
Dim rngCurrent As Range
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = New Scripting.Dictionary
For Each rngCurrent In Target
If Not dic.Exists(rngCurrent.Value) And rngCurrent.Value < Empty
Then 'Check the key
dic.Add rngCurrent.Value, rngCurrent.Value 'Add the item if
unique
End If
Next rngCurrent

Set CreateDictionary = dic
End Function

Private Function MatchedArray(ByVal Dic1 As Scripting.Dictionary, _
ByVal Dic2 As Scripting.Dictionary) As Variant
Dim dicItem As Variant
Dim aryMatched() As String
Dim lngCounter As Long

lngCounter = 0
For Each dicItem In Dic1
If Dic2.Exists(dicItem) Then 'Check the key
ReDim Preserve aryMatched(lngCounter)
aryMatched(lngCounter) = dicItem
lngCounter = lngCounter + 1
End If
Next dicItem

If lngCounter = 0 Then
MatchedArray = Empty
Else
MatchedArray = aryMatched
End If
End Function
--
HTH...

Jim Thomlinson


"Daminc" wrote:


I've spent the last 5-6 hours trying to solve this problem with no joy

I have one named range called Highlighted_names


Code:
--------------------
=OFFSET(Highlighted_data!$A$3,0,0,COUNTA(Highlight ed_data!$A:$A),1)
--------------------


and another called Downloaded_list


Code:
--------------------
=OFFSET(Download_sheet!$B$2,0,0,COUNTA(Download_sh eet!$B:$B),1)
--------------------


These are on 2 different sheets.

My hope is have a Marco that checks the cells in the first range and
compares it to the second range and Selects any matches.

I then intend to highlight the rows in which these matches occur.

Any help would be appreciated


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=473778


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Comparing 2 dynamic ranges for matching names


Cheers Tom, that code you gave helped a lot (it also gave me a better
understanding of coding so that's a double bonus :) )

Jim, I'll keep that code around for now because it will be an education
trying to decipher it with my meager knowledge. Still, when I do work it
out I'll know I've reached the next level (I wonder if I'll get a medal
or something ;) )

Cheers for your help guys.


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=473778

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing, Matching, and Sum formula ma New Users to Excel 6 April 30th 10 01:41 PM
Comparing two columns and finding matching names excelissue Excel Worksheet Functions 1 October 12th 07 12:53 AM
Sorting and matching rows of names with Socials with master list and eliminating the extra names Giacomo Excel Worksheet Functions 1 March 10th 07 01:52 AM
Dynamic Formulas with Dynamic Ranges Ralph Howarth Excel Worksheet Functions 5 January 21st 05 08:44 AM
comparing or matching corresponding value mary Excel Programming 6 January 17th 04 09:21 AM


All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"