Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need a macro to compare values in a workbook

I have a workbook with 52 worksheets. The first 2 hold base data fro the
rest. I need a macro that will compare one cell to a range of data from the
first 2 worksheets.
For example:on worksheet one I have a range a1:a500,consider this the base
data. On another worksheet i have one cell of data that needs to be compared
to the range mentioned above. If the data in the cell does not match the
range, it should change the data in the cell red.

As you can tell I am new at this, any help would be appreciated
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Need a macro to compare values in a workbook

If you select the cell you want to check and then run this macro the font
will turn red if the data is not found in the master list

Sub CheckData()
Dim foundCell As Range
Dim lookUp As String
lookUp = ActiveCell.Value
With Worksheets("Sheet1").Range("A1:A500")
Set foundCell = .Find(lookUp, LookIn:=xlValues)
End With
If foundCell Is Nothing Then ActiveCell.Font.ColorIndex = 3
End Sub

However there are several drawbacks to this method. For example, if you
subsequently change the data in the lookup cell to somthing that does exist
in the list the font will still be red.

A better way of doing this would be to use a formula like vlookup. Lets say
the value you want to check is in cell A2 on sheet 2. In cell B2 enter the
formula:

=IF(ISNA(VLOOKUP(A2,Sheet1!$A$1:$A$500,1,0)),"Not Found","")

You can then format the font in cell B2 to be large, bold and red or
whatever to make it more obvious.

Hope this helps
Rowan

"DVnet" wrote:

I have a workbook with 52 worksheets. The first 2 hold base data fro the
rest. I need a macro that will compare one cell to a range of data from the
first 2 worksheets.
For example:on worksheet one I have a range a1:a500,consider this the base
data. On another worksheet i have one cell of data that needs to be compared
to the range mentioned above. If the data in the cell does not match the
range, it should change the data in the cell red.

As you can tell I am new at this, any help would be appreciated
Thanks

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
Macro to copy values to Workbook KCG Excel Discussion (Misc queries) 10 November 6th 07 10:52 PM
Excel VBA Macro to compare 2 worksheets for same values [email protected] Excel Worksheet Functions 0 August 23rd 06 04:35 PM
Passing selected workbook name and values to a macro simora Excel Worksheet Functions 0 May 25th 05 07:24 PM
Excel Compare values in columns & display missing values in a new cpetta Excel Discussion (Misc queries) 1 April 2nd 05 05:51 AM
Macro to compare values and return exact matching value [email protected] Excel Programming 1 January 2nd 04 11:59 PM


All times are GMT +1. The time now is 03:23 AM.

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

About Us

"It's about Microsoft Excel"