|
▼En さん:
>B列の文字が「FFAAAJJ」のようなときも、C列には「10」とかえしたいのですが、
「AAA」を含む文字列かどうかの判定は
▼Like演算子とか、
Sub Try1()
Dim r As Range
Dim ss As String
Dim v
For Each r In Range("B5:B50")
ss = r.Value
v = Empty
Select Case True
Case ss Like "*AAA*": v = 10
Case ss Like "*BBB*": v = 20
Case ss Like "*CCC*": v = 30
End Select
r.Offset(, 1).Value = v
Next
End Sub
▼InStr関数 を使えばいいとおもいます。
Sub Try2()
Dim r As Range
Dim ss As String
Dim v
For Each r In Range("B5:B50")
ss = r.Value
v = Empty
If InStr(ss, "AAA") Then
v = 10
ElseIf InStr(ss, "BBB") Then
v = 20
ElseIf InStr(ss, "CCC") Then
v = 30
End If
r.Offset(, 2).Value = v
Next
End Sub
Sub Try3()
Dim r As Range
Dim ss As String
Dim v
For Each r In Range("B5:B50")
ss = r.Value
r.Offset(, 3).Value = _
Switch(InStr(ss, "AAA"), 10, _
InStr(ss, "BBB"), 20, _
InStr(ss, "CCC"), 30, _
1, Empty)
Next
End Sub
|
|