I appreciate you all in advance.
Now I'm struggle to break down VBA codes.
My demands are three.
1. Declare Public Variable
2.Use it in worksheet_change
3.Call certain procedure from worksheet_change
Thus I have three codes below, Code1 in worksheet module("Sheet1")
And Code2, 3 in standard module.
The problem is it occurs run time error5.
I googled but I cant find suitable resolve to this issue.
Any help and advice would be appreciated.
Code1.
Code2 , 3
Now I'm struggle to break down VBA codes.
My demands are three.
1. Declare Public Variable
2.Use it in worksheet_change
3.Call certain procedure from worksheet_change
Thus I have three codes below, Code1 in worksheet module("Sheet1")
And Code2, 3 in standard module.
The problem is it occurs run time error5.
I googled but I cant find suitable resolve to this issue.
Any help and advice would be appreciated.
Code1.
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, myRange) Is Nothing Then
Call ChangeColorYesNo(Target)
End If
End Sub
Code2 , 3
VBA Code:
Option Explicit
Public myRange As Range
Sub SetMyRange()
Set myRange = ThisWorkbook.Worksheets("Sheet1").Range("A1:A10")
End Sub
Sub ChangeColorYesNo(ByVal Target As Range)
Dim cell As Range
For Each cell In Intersect(Target, myRange)
If cell.Value = "Yes" Then
cell.Interior.Color = vbGreen
ElseIf cell.Value = "No" Then
cell.Interior.Color = vbRed
Else
' Do nothing
End If
Next cell
End Sub