Cells

I'm really confused as to why I activate a cell:

x = ActiveCell.Row

Yet when I try to select that cell:

Range (Cells(x, 1)).Select

It comes up with an address way out of whack! What am I doing wrong




Answer this question

Cells

  • sennekeennes

    It works because it is using the default property of a cell, which is .Value. And it just so happens the content of that cell is a valid cell address.

    The same effect with the property explicitly set.

    Range (Cells(x, 1).Value).Select


  • Penicillin

    Thanks for your reply. I think I figured out what is wrong, but I'm not sure how to fix it.

    The cell I am referring to has a number in it, P027812. The formula seems to be using that cell data as an address (coordinates) rather than just data. So when I try to select the range, it selects column "P" and row 27812.

    Any idea how I can fix this



  • Vladimir Chtepa

    Thanks...as you can tell I am just learning...and you taught me alot!

  • mschelstrate

    When the first argument of the Range method is used it needs the cells address, so this will work.

    x = ActiveCell.Row
    Range(Cells(x, 1).Address).Select

    Or you could shorten it to this.
    ActiveCell.EntireRow.Range("A1").Select



  • SoniqStylz

    Hi

    Your code should work, I got an error when I ran it on my machine (probably my typo). I changed the syntax slightly and it works fine. The selected cell always goes to the cell in column A of the current row. My routine is below:

    Public Sub test()
    Dim x As Long

    x = ActiveCell.Row
    Range("A" & Trim$(Str$(x))).Select

    End Sub

    Are you sure that your code does not change the value of x before the range select statement


  • Labm1ce

    BTW, why do you want to use Cells and Range both at same time You know if you do Cells(3, 2).Select, you select B3. Or you do Range("B3").Select. They are both Range object, thus does the same thing. You only need to use one of them.


  • Cells