Consulting

Results 1 to 4 of 4

Thread: Select a cell with target.row

  1. #1
    VBAX Regular
    Joined
    Dec 2018
    Posts
    23
    Location

    Select a cell with target.row

    Hi,

    I've got a problem in my Worksheet_SelectionChange event.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim SelectCel As Range
    Dim SelectCelOffset As Range
    
    With Sheets(1)
    
    
    Set SelectCel = .Cells(Target.Row, 2)
    SelectCelOffset = SelectCel.Offset(0, 2).Select
    MsgBox SelectCelOffset.Address
    
    
    End With
    
    
    End Sub
    I'm trying to activate the cells that is 2 columns after the one I select.
    But I've got an error message 91 on this line :

    SelectCelOffset = SelectCel.Offset(0, 2).Select
    Can someone help me ?

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi castak!
    Nice to meet you again.
    If the cell you want to select is not in this worksheet, you may activate another worksheet first.
    and you need to prevent chain reaction.

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    If it is in the same worksheet
    change code into below:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim SelectCel As Range
    Dim SelectCelOffset As Range
    With Sheets(1)
    
    Set SelectCel = .Cells(Target.Row, 2)
    Set SelectCelOffset = SelectCel.Offset(0, 2)
    MsgBox SelectCelOffset.Address
    
    End With
    
    End Sub

  4. #4
    VBAX Regular
    Joined
    Dec 2018
    Posts
    23
    Location
    Nice to meet you agin 大灰狼1976 too!

    All right it works now thank you very much!

Posting Permissions

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