+ Reply to Thread
Results 1 to 5 of 5

Find the previous row selected?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-11-2007
    Posts
    93

    Question Find the previous row selected?

    Hi ,I have a question,

    When user clicks on different cell the following function is called.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Now if ,imagine the user is in row 3 and he clicks on row 10, Worksheet_SelectionChange(ByVal Target As Range) function is called, Now in this function Target.Row will give the present row that is 10 ,

    but how can i find previous row which the user was in (i.e 3) ?

    Thank you.
    Glen

  2. #2
    Forum Contributor
    Join Date
    12-12-2006
    Location
    New Zealand
    Posts
    151
    You need to wrap code with code tags

    try:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Static OldTarget As String
        MsgBox OldTarget
        OldTarget = Target.Address
    End Sub

  3. #3
    Forum Contributor
    Join Date
    12-12-2006
    Location
    New Zealand
    Posts
    151
    Sorry my last post gave you the cell address I see you want the row try this:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Static OldTargetRow As Long
        MsgBox OldTargetRow
        If Not Target.Count > 1 Then
            OldTargetRow = Target.Row
        End If
    End Sub

  4. #4
    Registered User
    Join Date
    05-11-2007
    Posts
    93
    Thanks Reafidy,
    Thats wat i wanted.

    How does the oldTargetRow return the previous row without being initialized?

  5. #5
    Forum Contributor
    Join Date
    12-12-2006
    Location
    New Zealand
    Posts
    151
    Hi,

    Its due to being dimensioned as static. Im not good at explaining so from the help files:

    Static Statement

    Used at procedure level to declare variables and allocate storage space. Variables declared with the Static statement retain their values as long as the code is running.

+ 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