View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default compare two cell values on different sheets

Here's a couple of examples:

Sub test()
If Worksheets("sheet1").Range("A1").Value =
Worksheets("sheet2").Range("A1").Value Then
MsgBox "same"
Else
MsgBox "different"
End If
End Sub

Sub test2()
Dim rng1 As Range, rng2 As Range

Set rng1 = Worksheets("sheet1").Range("A1")
Set rng2 = Worksheets("sheet2").Range("A1")

If rng1.Value = rng2.Value Then
MsgBox "same"
Else
MsgBox "different"
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"sagarh " wrote in message
...
hi I am a newbie to excel vba programming so please forgive if this is a
silly question.
I have an excel spreadsheet with two worksheets sheet1 and sheet2. I
need to do an if statement that compares two cell values. The cells on
both sheets will already be active/selected.

Thanks for any help


---
Message posted from http://www.ExcelForum.com/