+ Reply to Thread
Results 1 to 2 of 2

Cells property

  1. #1
    Registered User
    Join Date
    12-15-2004
    Posts
    64

    Cells property

    I am trying to refer to A1 using the Cells property rather than using Range as i understand it is better practice and will help as i learn to use VBA. However i cannot seem to make it happen.

    Here is what i have using Range which works fine. Could anybody help by replacing it with the equivillant Cells property so i can see where i am going wrong?

    Sub CheckA1()

    If ActiveCell = Range("A1") Then
    MsgBox ("Active cell is A1")
    Else: MsgBox ("Active cell is NOT A1")
    End If

    End Sub

    Regards

    Adrian

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Adrian,

    The first step in using the Cells property is translating the range address into row and column numbers. Fortunately, VBA can do this for us.

    Example of Translating Range Address:

    With Range("A1")
    Row = .Row
    Col = .Column
    End With

    Now the numbers can then be plugged into the Cells property...

    Cells(Rol, Col). <other property>

    Converting Your Code:

    Sub CheckA1()

    With ActiveCell
    Row = .Row
    Col = .Column
    End With

    If Row = 1 And Col = 1 Then
    MsgBox ("Active cell is A1")
    Else: MsgBox ("Active cell is NOT A1")
    End If

    End Sub


    Hope this answers your question,
    Leith Ross

+ 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