Private Sub Worksheet_Change(ByVal Target As Range)
RunSql Target, Me.Range("a1")
End S
ub
Sub RunSql(Target As Range, rCell As Range)
On Error Resume Next
I
f Not Application.Intersect(Target, rCell) Is Nothing Then
If InStr(rCell.Value2, "mi_sql") > 0 Then
sql = Right(rCell.Value2, Len(rCell.Value2) - Len("mi_sql "))
Application.EnableEvents = False
run_sql_sub sql
Application.EnableEvents = True
End If
Exit Sub
E
nd If
Dim rInput As Range
Set rInput = rCell.Precedents
If Err.Number = 0 Then
If Not Application.Intersect(Target, rInput) Is Nothing Then
If InStr(rCell.Value2, "mi_sql") > 0 Then
sql = Right(rCell.Value2, Len(rCell.Value2) - Len("mi_sql "))
Application.EnableEvents = False
run_sql_sub sql
Application.EnableEvents = True
End If
End If
E
nd If
End Sub