ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   compare two cell values on different sheets (https://www.excelbanter.com/excel-programming/291438-compare-two-cell-values-different-sheets.html)

sagarh

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

Thanks for any hel

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


Rob van Gelder[_4_]

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/




sagarh[_2_]

compare two cell values on different sheets
 
What if the current selected cell is not A1 - my two sheets have 400
rows each and I am moving down the rows and doing a compare

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


Tom Ogilvy

compare two cell values on different sheets
 
Dim rng1 as Range, i as Long
Dim cell as Range
With worksheet("Sheet1")
set rng1 = .Range(.Cells(1,1),.Cells(1,1).End(xldown))
End With

i = 0
for each cell in rng1

if cell.Value < worksheets("Sheet2") _
.Range("A1").Offset(i,0).Value Then
' do what - they don't match
else
' do what - they match
End if
i = i + 1
Next


--
Regards,
Tom Ogilvy


"sagarh " wrote in message
...
What if the current selected cell is not A1 - my two sheets have 4000
rows each and I am moving down the rows and doing a compare.


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





All times are GMT +1. The time now is 05:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com