ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autorun a macro (https://www.excelbanter.com/excel-programming/283305-autorun-macro.html)

No Name

Autorun a macro
 
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

Chip Pearson[_2_]

Autorun a macro
 
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


wrote in message
...
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




No Name

Autorun a macro
 
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
-----Original Message-----
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
.



All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com