|
コードをまだ見て居ないのですが?
多分こんな事かと思いますが?
普通は変数の入替えをするのでは無く、
配列にデータを入れて、読み出しを工夫すると思うのですが?
例えば、読み出し順に規則性が無い場合は媒介変数を使って読み出します
また、規則性が有る様なら、「\」、「MOD」演算子を組み合わせて読み出し順を工夫します
Option Explicit
Sub 変数入れ替え2()
' 読み出しに規則性が無い場合
' 媒介変数を使用
Dim i As Long
Dim vntData As Variant
Dim vntPos As Variant
Dim vntResult As Variant
vntData = Array("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3")
Select Case Range("a1").Value
Case "い"
vntPos = Array(3, 4, 5, 6, 7, 8, 0, 1, 2)
Case "う"
vntPos = Array(6, 7, 8, 0, 1, 2, 3, 4, 5)
End Select
For i = 0 To UBound(vntPos)
vntResult = vntResult & vntData(vntPos(i))
Next i
Range("b1").Value = vntResult
End Sub
Sub 変数入れ替え3()
' 読み出しに規則性が有る場合
' 「\」、「MOD」演算子を使用
Dim i As Long
Dim vntData As Variant
Dim lngMax As Long
Dim lngPos As Long
Dim vntResult As Variant
vntData = Array("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3")
lngMax = UBound(vntData)
Select Case Range("a1").Value
Case "い"
For i = 0 To lngMax
lngPos = (i + 3) Mod (lngMax + 1)
vntResult = vntResult & vntData(lngPos)
Next i
Case "う"
For i = 0 To lngMax
lngPos = (i + 6) Mod (lngMax + 1)
vntResult = vntResult & vntData(lngPos)
Next i
End Select
Range("b1").Value = vntResult
End Sub
|
|