Simple Macro

S

sparx

Please can somebody help - I would ask if anybody could write a simple
macro where the macro would constantly monitor a specific cell in a
worksheet called "Access" - say cell B9 or so.

If the cell matches either the following 3 then run "macro1"

Be: Empty
Be: 00:00:00:00:00:00
Be: 00-00-00-00-00-00

If the cell matches anything else then run "macro2"

I then could add macro1 or macro2 vba.

Thanks
 
A

Ardus Petus

The following code should be pasted into worksheet's code
(right-click on sheet tab, select code)

'-----------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rWatch As Range
Set rWatch = Range("B9")
If Intersect(Target, rWatch) Is Nothing Then Exit Sub
Select Case rWatch.Value
Case "", _
"00:00:00:00:00:00", _
"00-00-00-00-00-00"
Call macro1
Case Else
Call macro2
End Select
End Sub

Sub macro1()
MsgBox "macro1"
End Sub

Sub macro2()
MsgBox "macro2"
End Sub
'-------------
 
M

Miguel Zapico

You may use a code like this in the Worksheet_change event for the Access
worksheet.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Address = "$B$9" Then
If (Target.Value = "" Or Target.Value = "00:00:00:00:00:00" Or
Target.Value = "00-00-00-00-00-00") Then
' Run macro 1 here
Else
' Run macro 2 here
End If
End If
End Sub

Hope this helps,
Miguel.
 
S

sparx

Hi there, ive tried your vba but cant get anything to run! any
suggestions - if it runs on your pc, is there a chance you can attach
your excel file to a reply?
 

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

Top