vba courses london - perform macro whenever sheet
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft VBA Training and help » vba courses london - Perform a macro whenever the Sheet is updated

vba courses london - Perform a macro whenever the Sheet is updated

resolvedResolved · Low Priority · Version Standard

replyReply Thu 18 Jan 2007, 16:24Delegate Julian said...

Julian has attended:
Excel VBA Intro Intermediate course

Perform a macro whenever the Sheet is updated

Hi there,
Everytime I change a drop down box or any data on the sheet changes I want a macro to execute. The macro is in place of a 'nested IF' formula as they are limited to 7 x IFs.

I remember from the course that if you put a proceedure in the 'ThisWorkbook' module it will execute when anything on a specified sheet is updated. but I cant make it work. I tried putting the following in:

Sub auto_change()
Range("C26").Select
If ActiveCell = 10 Then
Range("D26") = 0
ElseIf ActiveCell = 20 Then
Range("D26") = 1
ElseIf ActiveCell = 21 Then
Range("D26") = 2
ElseIf ActiveCell = 22 Then
Range("D26") = 3
ElseIf ActiveCell = 23 Then
Range("D26") = 4
ElseIf ActiveCell = 30 Then
Range("D26") = 5
ElseIf ActiveCell = 31 Then
Range("D26") = 6
ElseIf ActiveCell = 32 Then
Range("D26") = 7
ElseIf ActiveCell = 33 Then
Range("D26") = 8
End If
End Sub

Many thanks

julian

For upcoming training course dates see: Pricing & availability

replyReply Tue 23 Jan 2007, 09:38 Edited on Tue 23 Jan 2007, 09:39Trainer Carlos said...

RE: Perform a macro whenever the Sheet is updated

The macro won't work on its own. All you have done is save it in the Workbook's module. To run the code:

On the code page for the relevant worksheet

Create an event procedure for the Worksheet called

Worksheet_SelectionChange

Call the macro from it OR Copy the code into the procedure

If it still doen't work with this event, then try the Event procedure

Worksheet_Change

 

Vba tip:

Use VbNullString instead of

When needing to default a String variable back to it's default of "" use vbNullString as in the following example:

Sub ClearText()

Dim strEmpName As String

strEmpName = "John Smith"
MsgBox strEmpName

strEmpName = vbNullString
MsgBox strEmpName

End Sub

View all VBA hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard