Autorun a macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a macro set up to sort a list(s). Is it possible
to have the macro autorun if a value in the list is
updated?

Any help or suggestions are greatly appreciated
 
You can use the Change event procedure. In the code module for the
worksheet containing the list, uses the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("TheList")) Is Nothing Then
Application.EnableEvents = False
Range("TheList").Sort key1:=Range("TheList")(1, 1), _
order1:=xlAscending, header:=xlNo
Application.EnableEvents = True
End If
End Sub

Change "TheList" to the range in question.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Use the WorkSheet_Change event

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Isect As Range
Set Isect = Application.Intersect(Range("H16:H40"),
Target)

If Target.Count > 1 Then
Exit Sub
End If
If Isect Is Nothing Then
Do things...
Else
Do these things...
End If

End Sub

Hope it helps
Lars Kofod
Denmark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top