Auto run macro

  • Thread starter Thread starter Esradekan
  • Start date Start date
E

Esradekan

I have an array (B6:J21) that requires a macro being run (sorting
macro) when any figure in the array is changed. How can I run this
macro "on demand"??
 
The worksheet Change event could trigger the macro.
Also, A UDF/Calculate event combo could be used to sort your data.

"On Demand" sounds like you want a button, but the thread title sounds like you want to avoid the button.
 
Include the following macro in the wroksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set r = Range("B6:J21")
If Intersect(t, r) Is Nothing Then Exit Sub
Application.EnableEvents = False
Call yoursub
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 
From what you have said or pointed me to read, I take it that the
macro will not change or "sort" if there is a change by formula. Is
that right??

I tried this, and doesnt seem to work and I suspect that is the cause.

Esra
 
I do have a workbook where this exact thing happens, a "sort" macro is
executed on a change in the array, ,but it is someone elses work and
is password protected. I dont know what the password is. Is there a
way that I can view thw code used in that book? That may help me.

Esra
 

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