Thread: Automatic macro
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
h2fcell h2fcell is offline
external usenet poster
 
Posts: 30
Default Automatic macro

Mia, I'm using Excel 2007.

Getting Started With Events

The easiest way to start with events and event procedures is to allow the
VBA editor to build the shell code for you. In Excel, right click one of the
sheet tabs at the bottom of the main window and choose View Code from the
pop-up menu. This will open the VBA Editor to the code module associated with
that worksheet. In that code window you will see two drop down boxes at the
top of the code window.

Change the (General) setting to Worksheet and then change SeletionChange to
Change. This will add the event procedure declaration for the Change event to
the code module, as shown below:

Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

Within the Worksheet_Change procedure, you can add any code that you want to
take place when a cell value is changed. This event is raised automatically
by Excel when a cell's value is changed either by user input or by other VBA
code. It is not raised if the value of the cell is changed by a formula
calculation in that cell.

See my final code below.

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.ListObjects("Table1").AutoFilter.Apply Filter
With ActiveWorkbook.Worksheets("Sheet1").ListObjects("T able1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

You need to "Table1" with the name of your table and "Sheet1" with the name
of your sheet. You also have to establish a Sort to the Filter.

Hope that helps.

"Mia" wrote:

Hello,

I want to have a totaly automatic macro. With that I mean that everytime i
change
in cell A1 the macro should run. What I´m trying to do is a tabel that will
automatic
sort after changed parameters. Do anyone know how to do this?
I´l be wery grateful!

BR
Mia