Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all
I'm very very new to this, so I'm writing a very simple macro. What I want it to do is compare two cells and see if the contents are the same. The contents are non numeric however. Is there a 'is the same as' function or something? Thanks, J |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
the equal sign works for non-numeric data as well
if Range("A1").Value = Range("B9").value then However, it has to be an exact match. if lcase(Range("A1").Value) = lcase(Range("B9").value) then You can use strcomp if strcomp(Range("A1").Value,Range("b9").value,vbText Compare) = 0 then the vbTextcompare says to use a case insensitive evaluation. -- Regards, Tom Ogilvy "Josie" wrote: Hi all I'm very very new to this, so I'm writing a very simple macro. What I want it to do is compare two cells and see if the contents are the same. The contents are non numeric however. Is there a 'is the same as' function or something? Thanks, J |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Wicked! That works. Many thanks.
"Tom Ogilvy" wrote: the equal sign works for non-numeric data as well if Range("A1").Value = Range("B9").value then However, it has to be an exact match. if lcase(Range("A1").Value) = lcase(Range("B9").value) then You can use strcomp if strcomp(Range("A1").Value,Range("b9").value,vbText Compare) = 0 then the vbTextcompare says to use a case insensitive evaluation. -- Regards, Tom Ogilvy "Josie" wrote: Hi all I'm very very new to this, so I'm writing a very simple macro. What I want it to do is compare two cells and see if the contents are the same. The contents are non numeric however. Is there a 'is the same as' function or something? Thanks, J |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Josie, try this:
If Range("A1").Value = Range("A2").Value Then MsgBox "A1 and A2 have the same value" Else MsgBox "A1 and A2 have different values" End if Come to think of it, it depends on what exactly you mean by the "same contents". For example if A1 is 2 and A2 is =1+1 are they the same or different? If you want to count them as be different use .Formula instead of ..Value. If you want to compare their appearance (e.g. the same number with two different formats) use .Text hope this helps Andrew Josie (DONOTSPAM) wrote: Hi all I'm very very new to this, so I'm writing a very simple macro. What I want it to do is compare two cells and see if the contents are the same. The contents are non numeric however. Is there a 'is the same as' function or something? Thanks, J |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
For example if A1 is 2 and
A2 is =1+1 are they the same or different? What would you consider as numeric? <g -- Regards, Tom Ogilvy "Andrew Taylor" wrote: Josie, try this: If Range("A1").Value = Range("A2").Value Then MsgBox "A1 and A2 have the same value" Else MsgBox "A1 and A2 have different values" End if Come to think of it, it depends on what exactly you mean by the "same contents". For example if A1 is 2 and A2 is =1+1 are they the same or different? If you want to count them as be different use .Formula instead of ..Value. If you want to compare their appearance (e.g. the same number with two different formats) use .Text hope this helps Andrew Josie (DONOTSPAM) wrote: Hi all I'm very very new to this, so I'm writing a very simple macro. What I want it to do is compare two cells and see if the contents are the same. The contents are non numeric however. Is there a 'is the same as' function or something? Thanks, J |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
If cell equals a name then get data from column | Excel Worksheet Functions | |||
How to get less than dates if Data in another column equals data | Excel Worksheet Functions | |||
If a cell equals _, at the next row that equals _, return value fr | Excel Worksheet Functions | |||
if a:a (range) equals january and c:c equals gas then add g:g ($) | Excel Worksheet Functions | |||
custom filter does not work when selecting 'equals' X AND 'equals' | Excel Discussion (Misc queries) |