+ Reply to Thread
Results 1 to 5 of 5

How to test cell contents in a macro?

  1. #1
    Registered User
    Join Date
    02-22-2006
    Posts
    2

    How to test cell contents in a macro?

    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?

  2. #2
    Norman Jones
    Guest

    Re: How to test cell contents in a macro?

    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



    "JennyGard" <[email protected]> wrote
    in message news:[email protected]...
    >
    > 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?
    >
    >
    > --
    > JennyGard
    > ------------------------------------------------------------------------
    > JennyGard's Profile:
    > http://www.excelforum.com/member.php...o&userid=31803
    > View this thread: http://www.excelforum.com/showthread...hreadid=515272
    >




  3. #3
    Andrew Taylor
    Guest

    Re: How to test cell contents in a macro?

    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...


    JennyGard wrote:
    > 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?
    >
    >
    > --
    > JennyGard
    > ------------------------------------------------------------------------
    > JennyGard's Profile: http://www.excelforum.com/member.php...o&userid=31803
    > View this thread: http://www.excelforum.com/showthread...hreadid=515272



  4. #4
    Norman Jones
    Guest

    Re: How to test cell contents in a macro?

    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



    "Norman Jones" <[email protected]> wrote in message
    news:%[email protected]...
    > 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




  5. #5
    Registered User
    Join Date
    02-22-2006
    Posts
    2
    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?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1