View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Can VB determine location of last cell changed?

Items are finally beginning to appear in google groups and I
now can see my post from Saturday and the replies there.
I'm now waiting for Rick's next post in response to the
answers from his questions about my post.


Not sure why things are going so slowly in the other thread, but since you
can see the code I originally posted there, here is the answer I posted back
to you (in case it shows up quicker for you in this thread than in the
original thread)...

Let's use the idea I proposed. Add the following to a module...

Public InModule As Boolean

Put this procedure in the code window for the worksheet you want this
functionality on...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not InModule Then
Call YourMacro(Target.Row)
End If
InModule = False
End Sub

Here I have assumed your macro is named YourMacro (change it as appropriate)
and I further assumed it will be modified to take one argument, the row
number of the cell just changed by your typing in an entry. To add the
argument to your macro (it will cease to be a macro once you do this;
instead, it will just be a plain subroutine), just create an argument for it
between the parentheses where the macro is declared. For example, if you
current macro is declared like this...

Private Sub MyMacro()
'
' Your code is located here
'
End Sub

then simple make it look like this...

Private Sub MyMacro(CurrentRow As Long)
'
' Your code is located here - wherever you now refer to the row
' for the active cell, just use the CurrentRow argument instead.
'
End Sub

--
Rick (MVP - Excel)