Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 'equals' for non-numeric data

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 'equals' for non-numeric data

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 'equals' for non-numeric data

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default 'equals' for non-numeric data

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 'equals' for non-numeric data

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
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
If cell equals a name then get data from column JDB Excel Worksheet Functions 2 September 25th 08 12:15 AM
How to get less than dates if Data in another column equals data Dan Soleau Excel Worksheet Functions 6 November 16th 07 08:22 PM
If a cell equals _, at the next row that equals _, return value fr CathyH Excel Worksheet Functions 10 May 2nd 07 07:53 PM
if a:a (range) equals january and c:c equals gas then add g:g ($) BCOz Excel Worksheet Functions 4 December 29th 05 07:40 PM
custom filter does not work when selecting 'equals' X AND 'equals' plindman Excel Discussion (Misc queries) 1 June 1st 05 11:29 PM


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