Finding Values in a Column Matching to a different workbook

  • Thread starter Thread starter Diana
  • Start date Start date
D

Diana

I am having trouble with a report...

Example:

A workbook of all the clients for the month and a workbook of zip codes in
High Risk areas. I need a quick solution to test if the monthly clients have
a zip code in the list of High risk zip codes. There are over 500 clients to
look up and currently I've been using the Control-F function to see if the
zips are in the list and it is very time consuming!

Please let me know if you all have any suggestions.

Thanks!
 
Add a new row 1.

Type the zipcode you're searching for in A1.

Then in B1, put this formula:
=countif(a3:A999,a1)
And you'll see the number of cells in that A3:A999 range that match the zip in
A1.

You may want to try adding an autofilter to that column and you could filter to
show any rows that match the zip code you're searching for.
 
As a v.simple illustration ..

In the same book,
let's say you have the high risk zip codes listed in A1 down in a sheet: z,
and you have the zip codes of your 500 clients listed in B2 down in another
sheet: Clients

In Clients,
You could place this in say, C2:
=IF(COUNTIF(z!A:A,B2),"Yes","")
Copy C2 down to the extent of data in col B. Then just enter a label into
C1, apply autofilter on col C, filter out: Yes. These will be results that
you seek.
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:20,000 Files:362 Subscribers:62
xdemechanik
 
Hi,

Use conditional formatting. Suppose you have a list of high risk zip code
in column A1:A10 and your client zip codes in D1:D700

Highligh the client zip codes and choose Format, Conditional formatting,
from the first drop down pick Formula is and in the second box enter
=OR($A$1:$A$10=D1)
Click Format and choose a color on the Patterns tab and click OK twice.

If this helps, please click the Yes button.
 
Sorry but these are not working! The Conditional Formatting worked for some
of the codes, turning them the color, but not all of the ones I know are in
the list.

The =IF(COUNTIF) is not working at all!

If anyone else has a solution or has insight as to why I can't get these
formulas to work please help!
 
All the solutions given had to assume certain things about your data -
sheet names you used, the columns and ranges of your data etc, and so
you had to amend these to suit your actual data. If you give details
of the ranges that you actually use, then the solutions can be
tailored to your requirements, so that you don't have to introduce
another possible source or error in the translation.

It is also useful to give some examples of your data - it occurs to me
that you might have some data that looks like numbers but is actually
text, whereas you are searching for numbers, or vice-versa.

Hope this helps.

Pete
 
This is great! Thank you!

Question: Is there are way to do this if the number is contained in the
list? Example: Some of the high risk zip codes show up as the 9-digit zip
code, and not the 5-digit that the list contains. Is there a way to not get
the exact number but if it contains it?

Thanks!
 
If you add a value to list that contains five numbers (or any other partial
match entered) from nine numbers in your high risk zip codes you can get it
to highlight with a different formula. Using Debra's example, applying this
to cell A2. Modify the cell condition to:

=FIND(A2,CodeList)>0

The above will result in both partial matches and blank cells highlighting.
To suppress blank highlights, you need to add a further condition (as
condition 1, the above becoming condition 2) :

=ISERROR(FIND(A2,CodeList))

One you have the condition working:
- Copy A2
- Select the area where you want the conditional formatting copied
- Paste special, formats.


HTH
 
This is very confusing. : (

Here is an example:

A B
Zip HighRisk Zips
80302 80302
803025698 91568
91056 78595
91568
71485
62185
94851694
785951561
184860


So I know I would Highlight the High Risk Zips, label them HIGH in the name
box. Then, use conditional formatting for zip =COUNTIF(HIGH,A2) and have
them all turn blue. My problem is that for example, in A2 there is the
9-digit zip code, and in the HIGH colunm it is only 5 digits.

The last example you gave me to help, I would add to the conditional
formatting of the zip with the =COUNTIF. Is this wrong? Because when I do,
all the numbers end up turning blue, therefore seems not to be working.
Please clarify. Thank you so much for your help. I really appreciate it.
 
That is the reverse of how I perceived your problem. Performing this is more
complex and (as far as I know) cannot be done with conditional formatting.
You will need to use VBA.

Right-click on the tab or the worksheet in which you need the highlighting
work performed.
Copy and past the code below my sig (everything between asterisks).

Some instructions for use:

1) Where you see highRiskRange = "high" in the code below, you can change
"High" to the range of cells or named range of your high risk zip codes.
Just make sure the quote marks are retained with any different name.
Examples:
highRiskRange = "Z1:Z20"
highRiskRange = "highRiskZips"

2) Where you see zipsToCheck = "A:A" in the code below, you can change "A:A"
in a similar manner to pick up the range where zips are entered. For
example, to pick up column C
zipsToCheck = "C:C"

3) Highlighting is currently set to light yellow. To choose a different
colour for you highlighting find the colour you like under 'interior' in the
table on the following web page.
http://www.mvps.org/dmcritchie/excel/colors.htm

After finding the number of the colour of your choice, change the line
myColor = 36 to myColor = {your chosen number}. Example, if you like red
change it to
myColor = 3 'red

4) I set a minimum high risk zip code length of five characters. If you need
to pick up shorter target zips, change the following line
minZipLength = 5

5) If after pasting, any of the code is showing in red font, it means that
text wrapping went awry. Just go to the end of the line above the red text
and press [delete]

Notes

Anything in a VBA line following a single quote is treated as comment so,
you could just change it to
myColor = 3

Changing cell colour effect border colour so, I did some border work in the
code to approximate standard Excel visuals.

For efficiency, the code is set to exit if there is a multi-cell change.
This is mainly to allow for deletions but, it also prevents checking if the
fill-handle is used.

I ran up the code relatively quickly, testing it on a small range of
scenarios. If you strike problems or need explanations, feel free to ask.


HTH
--
Steve

'*****************************************
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c
Dim isect
Dim tgtAddr
Dim zipsToCheck
Dim highRiskRange
Dim myColor
Dim minZipLength

minZipLength = 5 'the minimum length of high risk zips
myColor = 36 ' light yellow
highRiskRange = "high"
zipsToCheck = "A:A" 'set to look at column A.
'Change to your column
'or your named range

tgtAddr = Target.Address 'Do not change

Set isect = Application.Intersect(Range(zipsToCheck), Range(tgtAddr))
If isect Is Nothing Then
'Value not in column A
Else
'format if in high list

Range(tgtAddr).Interior.ColorIndex = xlNone 'remove existing
interior color

On Error GoTo Worksheet_Change_Exit ' exits on multi-cell changes
' such as the fill handle

If Range(tgtAddr).Value & "" <> "" And Len(Range(tgtAddr).Value) >=
minZipLength Then
For Each c In Range(highRiskRange)

If InStr(c.Value, Range(tgtAddr).Value) > 0 Then
With Range(tgtAddr)
.Interior.ColorIndex = myColor
End With
With Range(tgtAddr).Borders()
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
Exit Sub
End If

Next c
End If
End If

Worksheet_Change_Exit:

End Sub


'*****************************************



Diana said:
This is very confusing. : (

Here is an example:

A B
Zip HighRisk Zips
80302 80302
803025698 91568
91056 78595
91568
71485
62185
94851694
785951561
184860


So I know I would Highlight the High Risk Zips, label them HIGH in the
name
box. Then, use conditional formatting for zip =COUNTIF(HIGH,A2) and have
them all turn blue. My problem is that for example, in A2 there is the
9-digit zip code, and in the HIGH colunm it is only 5 digits.

The last example you gave me to help, I would add to the conditional
formatting of the zip with the =COUNTIF. Is this wrong? Because when I
do,
all the numbers end up turning blue, therefore seems not to be working.
Please clarify. Thank you so much for your help. I really appreciate it.
 
Forgot to mention

The main instruction - this code works when a new zip is added to column A.

If this does the job, you need to let me know whether you would like it to
run on existing data as well as checking a value when entered (as it does
now) If you need to perform the check on a range of existing values (such as
after your target zips change or new values are added with copy/paste) more
work is required and a change of approach. The present method of looping
through cells in a lookup list should not be too slow but looping through
cells and for each cell looping through a lookup list could be painfully
slow. So let me know if you need to use the code to update highlighting to
more than one value at a time. Make sure you test the code thoroughly by
entering zips in every possible combination before feeding back.

--
Steve

AltaEgo said:
That is the reverse of how I perceived your problem. Performing this is
more complex and (as far as I know) cannot be done with conditional
formatting. You will need to use VBA.

Right-click on the tab or the worksheet in which you need the highlighting
work performed.
Copy and past the code below my sig (everything between asterisks).

Some instructions for use:

1) Where you see highRiskRange = "high" in the code below, you can change
"High" to the range of cells or named range of your high risk zip codes.
Just make sure the quote marks are retained with any different name.
Examples:
highRiskRange = "Z1:Z20"
highRiskRange = "highRiskZips"

2) Where you see zipsToCheck = "A:A" in the code below, you can change
"A:A" in a similar manner to pick up the range where zips are entered. For
example, to pick up column C
zipsToCheck = "C:C"

3) Highlighting is currently set to light yellow. To choose a different
colour for you highlighting find the colour you like under 'interior' in
the table on the following web page.
http://www.mvps.org/dmcritchie/excel/colors.htm

After finding the number of the colour of your choice, change the line
myColor = 36 to myColor = {your chosen number}. Example, if you like red
change it to
myColor = 3 'red

4) I set a minimum high risk zip code length of five characters. If you
need to pick up shorter target zips, change the following line
minZipLength = 5

5) If after pasting, any of the code is showing in red font, it means that
text wrapping went awry. Just go to the end of the line above the red text
and press [delete]

Notes

Anything in a VBA line following a single quote is treated as comment so,
you could just change it to
myColor = 3

Changing cell colour effect border colour so, I did some border work in
the code to approximate standard Excel visuals.

For efficiency, the code is set to exit if there is a multi-cell change.
This is mainly to allow for deletions but, it also prevents checking if
the fill-handle is used.

I ran up the code relatively quickly, testing it on a small range of
scenarios. If you strike problems or need explanations, feel free to ask.


HTH
--
Steve

'*****************************************
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c
Dim isect
Dim tgtAddr
Dim zipsToCheck
Dim highRiskRange
Dim myColor
Dim minZipLength

minZipLength = 5 'the minimum length of high risk zips
myColor = 36 ' light yellow
highRiskRange = "high"
zipsToCheck = "A:A" 'set to look at column A.
'Change to your column
'or your named range

tgtAddr = Target.Address 'Do not change

Set isect = Application.Intersect(Range(zipsToCheck), Range(tgtAddr))
If isect Is Nothing Then
'Value not in column A
Else
'format if in high list

Range(tgtAddr).Interior.ColorIndex = xlNone 'remove existing
interior color

On Error GoTo Worksheet_Change_Exit ' exits on multi-cell
changes
' such as the fill handle

If Range(tgtAddr).Value & "" <> "" And Len(Range(tgtAddr).Value) >=
minZipLength Then
For Each c In Range(highRiskRange)

If InStr(c.Value, Range(tgtAddr).Value) > 0 Then
With Range(tgtAddr)
.Interior.ColorIndex = myColor
End With
With Range(tgtAddr).Borders()
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
Exit Sub
End If

Next c
End If
End If

Worksheet_Change_Exit:

End Sub


'*****************************************



Diana said:
This is very confusing. : (

Here is an example:

A B
Zip HighRisk Zips
80302 80302
803025698 91568
91056 78595
91568
71485
62185
94851694
785951561
184860


So I know I would Highlight the High Risk Zips, label them HIGH in the
name
box. Then, use conditional formatting for zip =COUNTIF(HIGH,A2) and have
them all turn blue. My problem is that for example, in A2 there is the
9-digit zip code, and in the HIGH colunm it is only 5 digits.

The last example you gave me to help, I would add to the conditional
formatting of the zip with the =COUNTIF. Is this wrong? Because when I
do,
all the numbers end up turning blue, therefore seems not to be working.
Please clarify. Thank you so much for your help. I really appreciate
it.
 
Back
Top