Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



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
Auto generate sheets by different values of a cell. Dawn Excel Discussion (Misc queries) 5 October 29th 12 08:49 PM
Compare Sheets values in two colums Geir[_2_] Excel Worksheet Functions 1 April 7th 08 01:55 PM
Compare cell values Grant Excel Worksheet Functions 5 February 24th 05 10:54 AM
how do i compare 2 spread sheets if the content of a cell is avai. Hayitsme Excel Worksheet Functions 1 December 16th 04 11:27 PM


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