preceding cell identification



  • preceding cell identification
    di last cell (utente non iscritto) data: 09/08/2014 15:41:23

    Hi everybody ,

    I am struggling to find a way to keep track of the cell i am from . said in other way "activecell.row" "active cell.column" it is related to the current position i would like to find a way to know same information but related to the preceding cell.

    many thanks



  • di lepat (utente non iscritto) data: 09/08/2014 17:14:23

    try this code
     
    Dim cell As Range
    Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    MsgBox ("current cell " & Target.Address)
    MsgBox ("Previous cell " & cell.Address)
    Set cell = Target
    End Sub



  • di scossa data: 09/08/2014 18:16:02

    Hi,

    if you want to keep track even if you close the file, try this:

    First step: select a cell and assign it the name PrevCell;

    Second step: insert the code below in the class module of ThisWorkbook.

    Hope this help.

    scossa's web site
    Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno.
    Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw)

     
    Private Sub Workbook_SheetDeActivate(ByVal Sh As Object)
      MsgBox "ActiveCell: " & ActiveCell.Address(0, 0, external:=True) & vbCrLf & _
        "PrevCell: " & [PrevCell].Address(0, 0, external:=True)
      'Me.Names("PrevCell").RefersTo = "=" & ActiveCell.Address(external:=True)
    End Sub
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
      MsgBox "ActiveCell: " & ActiveCell.Address(0, 0, external:=True) & vbCrLf & _
        "PrevCell: " & [PrevCell].Address(0, 0, external:=True)
      Me.Names("PrevCell").RefersTo = "=" & ActiveCell.Address(external:=True)
    End Sub