Share via

Excel VBA: conoscere cella di partenza

Anonymous
2017-12-18T10:30:14+00:00

Buongiorno,

in una macro VBA in Excel, dovrei poter conoscere la cella di partenza, ma non riesco a capire come fare.

Il problema è questo: supponiamo di modificare la cella A1 e poi mi sposto in altra cella (con tasti-freccia, enter o mouse). Con "ActiveCell" ho i dati dove sono posizionato dopo essermi spostato, ma io vorrei sapere cos'è scritto in A1 (che è la cella modificata, da cui sono partito).

Grazie per l'aiuto e buona giornata

Ivo

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2017-12-18T11:08:55+00:00

    You have to detect the last changed cell (resp. cells) by yourself.

    Andreas.

    Option Explicit

    Dim LastTarget As Range, LastActiveCell As Range

    Private Sub Worksheet_Change(ByVal Target As Range)

      'Check previous cell

      If LastActiveCell Is Nothing Then

        'No previous cell => 1st change

      Else

        Debug.Print "LastActiveCell ", LastActiveCell.Address

      End If

      If LastTarget Is Nothing Then

        'No previous cell => 1st change

      Else

        Debug.Print "LastTarget ", LastTarget.Address

      End If

      Set LastTarget = Target

      Set LastActiveCell = ActiveCell

    End Sub

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2017-12-18T11:51:33+00:00

    Thank you very much!

    Ivo

    0 comments No comments