+ Reply to Thread
Results 1 to 4 of 4

How do I refer to a cell in an If statement in VBA?

  1. #1
    Forum Contributor
    Join Date
    02-09-2011
    Location
    Perth, Australia
    MS-Off Ver
    2016
    Posts
    161

    How do I refer to a cell in an If statement in VBA?

    Hi Forum,

    I am trying to figure out how to refer to a cell when using a simple If statement.

    The code below runs the message whenever I change the value of any cell.

    I am trying to set it up so that it only applies to cell A2.

    At present it seems to ignore the If. I suspect that I am not refering to cell A2 properly.



    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells <> "A2" Then Exit Sub

    MsgBox "A2 Changed"

    End Sub




    Can anyone help, please?


    Thanks very much

    Dave

  2. #2
    Forum Contributor
    Join Date
    01-13-2013
    Location
    Oklahoma
    MS-Off Ver
    Office 2007 / Office 2010
    Posts
    123

    Re: How do I refer to a cell in an If statement in VBA?

    Try this
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-09-2011
    Location
    Perth, Australia
    MS-Off Ver
    2016
    Posts
    161

    Re: How do I refer to a cell in an If statement in VBA?

    Thanks very much, Yraen.

    This has helped me get it working.


    Regards

    Dave

  4. #4
    Forum Contributor
    Join Date
    01-13-2013
    Location
    Oklahoma
    MS-Off Ver
    Office 2007 / Office 2010
    Posts
    123

    Re: How do I refer to a cell in an If statement in VBA?

    You're welcome, I'm glad it's working for you.

+ 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