|
kawataです、よろしくお願いします。
ichinoseさん、bikynさん、どうもありがとうございました、
どうにかこうにか、やりたいことの形が見えてきました。
<データ>
a b c
1 a001 a002 a003
2 b001 b002 c001
3 c002 b003 c003
4 a004 b004 c004
(以下、続く)
Sub testz()
Dim MyArray As Variant
Dim MyArray1() As Variant
Dim MyArray2() As Variant
Dim MyArray3() As Variant
Dim m As Long, n As Long
Dim j1 As Long, j2 As Long, j3 As Long
With Sheets("Sheet2")
e_row = .UsedRange.Rows.Count
MyArray = .Range("a1:c" & e_row).Value
j1 = 1: j2 = 1: j3 = 1
For n = 1 To e_row
For m = 1 To 3
chk = Left(MyArray(n, m), 1)
Select Case chk
Case "a"
ReDim Preserve MyArray1(1 To 1, 1 To j1)
MyArray1(1, j1) = MyArray(n, m)
j1 = j1 + 1
Case "b"
ReDim Preserve MyArray2(1 To 1, 1 To j2)
MyArray2(1, j2) = MyArray(n, m)
j2 = j2 + 1
Case "c"
ReDim Preserve MyArray3(1 To 1, 1 To j3)
MyArray3(1, j3) = MyArray(n, m)
j3 = j3 + 1
End Select
j = j + 1
Next
Next
.Range("d1").Resize(, UBound(MyArray1, 2)).Value = MyArray1
.Range("d2").Resize(, UBound(MyArray2, 2)).Value = MyArray2
.Range("d3").Resize(, UBound(MyArray3, 2)).Value = MyArray3
End With
End Sub
まだまだスッキリしたコードとはいえませんが、とにかく配列を習得したいが
ためにということで数をこなしていきたいと思います。(^^;。
ありがとうございました!!。
またよろしくお願いします。
|
|