Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 28
Default macro for same value in 2 different sheets

Hii all
I am trying to write a macro to compare first 50 values of, say column
A of sheet 1 and column B of sheet 2. I want the macro to highlight
only those cells of column A that equal to sheet 2 column B values.
thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default macro for same value in 2 different sheets

try this macro. To use, highlight cells in column A on Sheet1. the macro
will compare these same rows in Sheet2 in column B

Sub CompareSh1Sh2()

Const FirstSheet = "Sheet1"
Const SecondSheet = "Sheet2"
Const FirstSheetCol = 1
Const SecondSheetCol = 2

Worksheets(FirstSheet).Activate
Lastrow = ActiveCell.End(xlDown).Row
Set MyRange = Range(Cells(ActiveCell.Row, FirstSheetCol), _
Cells(Lastrow, FirstSheetCol))
For Each Cell In MyRange
SecondCell = Worksheets(SecondSheet). _
Cells(Cell.Row, SecondSheetCol)
If (Cell = SecondCell) Then
Cell.Interior.ColorIndex = 4
Else
Cell.Interior.ColorIndex = xlNone
End If
Next Cell

End Sub

"sharmashanu" wrote:

Hii all
I am trying to write a macro to compare first 50 values of, say column
A of sheet 1 and column B of sheet 2. I want the macro to highlight
only those cells of column A that equal to sheet 2 column B values.
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
Add sheets using macro Heine Excel Worksheet Functions 11 November 3rd 06 02:06 PM
macro for new sheets Raza Excel Worksheet Functions 2 November 8th 05 06:10 PM
macro/new sheets daolb Excel Discussion (Misc queries) 5 June 29th 05 10:59 AM
macro to hide sheets ditchy Excel Discussion (Misc queries) 8 May 2nd 05 02:21 AM
Macro for moving sheets minhao Excel Discussion (Misc queries) 3 December 10th 04 08:09 AM


All times are GMT +1. The time now is 03:07 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"