Option
Explicit
Sub
Example1()
Range(
"A1:A4"
).Value = WorksheetFunction.Transpose(Array(
"Str1"
,
"Str3"
,
"Str4"
,
"Str2"
))
Dim
regexp
As
Object
Dim
rngCell
As
Excel.Range
Set
regexp = CreateObject(
"VBScript.RegExp"
)
regexp.Pattern =
"^Str[1-2]$"
For
Each
rngCell
In
Range(
"A1:A4"
).Cells
Debug.Print rngCell.Address(0, 0);
"{'"
;
CStr
(rngCell.Value);
"'}:"
;
If
regexp.Test(rngCell.Value)
Then
Debug.Print Spc(2);
"match"
Else
Debug.Print Spc(2);
"no_match"
End
If
Next
Set
regexp =
Nothing
End
Sub
Sub
Example2()
Range(
"A1:A4"
).Value = WorksheetFunction.Transpose(Array(
"Str1"
,
"Str3"
,
"Str4"
,
"Str2"
))
Dim
rngCell
As
Excel.Range
For
Each
rngCell
In
Range(
"A1:A4"
).Cells
Debug.Print rngCell.Address(0, 0);
"{'"
;
CStr
(rngCell.Value);
"'}:"
;
Select
Case
rngCell.Value
Case
"Str1"
,
"Str2"
Debug.Print Spc(2);
"match"
Case
Else
Debug.Print Spc(2);
"no_match"
End
Select
Next
End
Sub