Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

How to test cell contents in a macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JennyGard - 22 Feb 2006 12:13 GMT
I'm using MS Excel 2000, and I want to write a macro that tests cell
contents.  Unfortunately, after a couple hours of looking at help files
(MS Visual Basic 6.0), I have found no method to do so.

My code concept is
If Cellcontents(activecell) = "dog" then
DoSomething
EndIf

This used to be so easy in Lotus 1-2-3...haha, way back in the
pre-Win95 era!  Can someone point me on the right track?

Signature

JennyGard

Norman Jones - 22 Feb 2006 12:27 GMT
Hi Jenny,

Try:

   If Range("A1").Value = "dog" Then
       'Your code
   Else
       'Do something else
   End If

Or, if case is unimportant:

   If LCase(Range(2A1").Value) = "dog" Then

---
Regards,
Norman

> I'm using MS Excel 2000, and I want to write a macro that tests cell
> contents.  Unfortunately, after a couple hours of looking at help files
[quoted text clipped - 7 lines]
> This used to be so easy in Lotus 1-2-3...haha, way back in the
> pre-Win95 era!  Can someone point me on the right track?
Norman Jones - 22 Feb 2006 12:58 GMT
Hi Jenny.

There is a typo:

>    If LCase(Range(2A1").Value) = "dog" Then

should read

If LCase(Range("A1").Value) = "dog" Then

(2 ==> ")

---
Regards,
Norman

> Hi Jenny,
>
[quoted text clipped - 13 lines]
> Regards,
> Norman
JennyGard - 22 Feb 2006 15:08 GMT
Thanks, guys!
Both methods worked, and they were easy...just as I suspected...but I
just couldn't quite figure it out for myself.  The MS VB help files
certainly do not seem geared for beginners.  Is there a good online
introduction to Excel macro programming?

Signature

JennyGard

Andrew Taylor - 22 Feb 2006 12:31 GMT
If ActiveCell.Value = "dog" Then...

You can even omit the .Value as it is the default property of the
ActiveCell object: If ActiveCell = "dog" Then...

> I'm using MS Excel 2000, and I want to write a macro that tests cell
> contents.  Unfortunately, after a couple hours of looking at help files
[quoted text clipped - 13 lines]
> JennyGard's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=31803
> View this thread: http://www.excelforum.com/showthread.php?threadid=515272
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.