|
▼あや さん:
とりあえず(?)グループすべてがない場合にメッセージをだして終わるパターンです。
Sub Sample7_3()
Dim f As Range
Dim f2 As Range
Dim r As Range
With Sheets("Sheet1")
Set r = .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
End With
Set f = r.Find(What:="れもん", LookAt:=xlWhole)
If f Is Nothing Then
MsgBox "黄色がない"
Exit Sub
End If
Set f = r.Find(What:="いちご", LookAt:=xlWhole)
Set f2 = r.Find(What:="りんご", LookAt:=xlWhole)
If f Is Nothing And f2 Is Nothing Then
MsgBox "赤色がない"
Exit Sub
End If
Set f = r.Find(What:="ぶどう", LookAt:=xlWhole)
If f Is Nothing Then
MsgBox "紫色がない"
Exit Sub
End If
End Sub
Sub Sample8_3()
Dim f As Range
Dim r As Range
Dim w As Variant
Dim v As Variant
Dim ans As String
Dim cnt As Long
With Sheets("Sheet1")
Set r = .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
End With
For Each w In Array(Array("れもん"), Array("いちご", "りんご"), Array("ぶどう"))
cnt = 0
For Each v In w
Set f = r.Find(What:=v, LookAt:=xlWhole)
If f Is Nothing Then
ans = ""
Select Case v
Case "れもん"
ans = "黄色"
Case "いちご", "りんご"
ans = "赤色"
Case "ぶどう"
ans = "紫色"
End Select
cnt = cnt + 1
End If
Next
If cnt = UBound(w) + 1 Then
MsgBox ans & " がない"
Exit Sub
End If
Next
End Sub
|
|