あなたSelect Case
文は間違って書かれています。また、2次元(行のX列)オブジェクトとしてRangeHolder
を処理する必要があります。 (エラーが発生することはありません一次元として扱うが、あなたがやろうとしているものになることはほとんどありません。それは別のユーザーを混乱状況にthis questionを参照してください。)
Option Explicit
Sub Szukanka()
Dim UpRow As Integer, DownRow As Integer, RangeHolder As Range
Dim x
x = 1
UpRow = 1
DownRow = 5
Set RangeHolder = Range(Cells(UpRow, 1), Cells(DownRow, 4))
Dim Good As Boolean
For x = 1 To 4
Good = False
Select Case RangeHolder(1, x).Value
Case "Dana wartosc"
Good = x = 1
Case "a"
Good = x = 2
Case "b"
Good = x = 3
Case "c"
Good = x = 4
End Select
If Good Then
MsgBox "It's good"
Else
MsgBox "It's bad " & RangeHolder(1, x)
End If
Next x
End Sub
私が書くことを試みました上記のSelect Case
は、私があなたがやろうとしていることをしていると思います(つまり、最初の行がヘッダーとして正しい値であることを確認してください)。しかし、それは本当にSelect Case
構造に向いていない、とあなたはあなたのSelect Case
が働いていなかった理由をIf
声明
Option Explicit
Sub Szukanka()
Dim UpRow As Integer, DownRow As Integer, RangeHolder As Range
Dim x
x = 1
UpRow = 1
DownRow = 5
Set RangeHolder = Range(Cells(UpRow, 1), Cells(DownRow, 4))
Dim CorrectValues As Variant
CorrectValues = Array("Dana wartosc", "a", "b", "c")
For x = 1 To 4
If RangeHolder(1, x).Value = CorrectValues(x - 1) Then
MsgBox "It's good"
Else
MsgBox "It's bad " & RangeHolder(1, x)
End If
Next x
End Sub
理由として、それを書いたほうが良いでしょう:
元のSelect Case
の文が等価ブロックIf
の文として書き直された場合、次のようになります。
If RangeHolder(x) = (RangeHolder(1) = "Dana wartosc") Then
MsgBox ("Its good")
ElseIf RangeHolder(x) = (RangeHolder(2) = "a") Then
MsgBox ("Its good")
ElseIf RangeHolder(x) = (RangeHolder(3) = "b") Then
MsgBox ("Its good")
ElseIf RangeHolder(x) = (RangeHolder(4) = "c") Then
MsgBox ("Its good")
Else
MsgBox ("Its bad" + RangeHolder(x))
End If
RangeHolder(x)
の値は"a"
た場合(及びRangeHolder(1)
"Dana wartosc"
た、RangeHolder(2)
RangeHolder(3)
は"b"
であり、RangeHolder(4)
は"c"
た、"a"
であった)、次いでなること:それは(
If "a" = True Then
MsgBox ("Its good")
ElseIf "a" = True Then
MsgBox ("Its good")
ElseIf "a" = True Then
MsgBox ("Its good")
ElseIf "a" = True Then
MsgBox ("Its good")
Else
MsgBox ("Its bad" + "a")
End If
"a"
としては= True
ないであろうこのように記述されている場合は実際に型の不一致を与えますが、Select Case
構文ではない場合)、Else
式が呼び出されます。
あなたはスクリーン - を投稿することができますあなたの 'RangeHolder'のショット?ヘッダーを探している「Range」を見ることができますか? –
'Select Case'ステートメントは、いくつかのブール式(' RangeHolder(1)= "Dana wartosc")を 'RangeHolder(x)'の値と比較しています。 – YowE3K