Hi, I have two ranges (5k cells each) that I want to read into two arrays, combine and then output to a range. The combined array should contain the first cell of range1 and each cell of range2, the second cell of range1 and each cell of range2, etc. as follows:
AX
AY
AZ
BX
BY
BZ
CX
CY
CZ
The following code works fine when outputting to a msgbox, but not to a range. Instead I get:
AZ
BZ
CZ
It's been 3-4 years since I wrote any code! Can someone help? Thanks!
code:
------------------------------------------------------------Sub KData()
Dim vaSData As Variant
Dim vaCData As Variant
Dim vaSData1 As Variant
Dim i As Long
Dim i1 As Long
vaSData = Range("A10:b16"
.Value
vaSData1 = Range("c10:c16"
.Value
ReDim vaCData(1 To UBound(vaSData, 1), 1 To 2)
For i = 1 To UBound(vaSData, 1)
For i1 = 1 To UBound(vaSData1, 1)
'MsgBox vaSData(i, 1)
'MsgBox vaSData1(i1, 1)
vaCData(i, 1) = vaSData(i, 1)
vaCData(i, 2) = vaSData1(i1, 1)
Next i1
Next i
Range("f1"
.Resize(UBound(vaSData, 1), 2).Value = vaCData
End Sub
------------------------------------------------------------
AX
AY
AZ
BX
BY
BZ
CX
CY
CZ
The following code works fine when outputting to a msgbox, but not to a range. Instead I get:
AZ
BZ
CZ
It's been 3-4 years since I wrote any code! Can someone help? Thanks!
code:
------------------------------------------------------------Sub KData()
Dim vaSData As Variant
Dim vaCData As Variant
Dim vaSData1 As Variant
Dim i As Long
Dim i1 As Long
vaSData = Range("A10:b16"
vaSData1 = Range("c10:c16"
ReDim vaCData(1 To UBound(vaSData, 1), 1 To 2)
For i = 1 To UBound(vaSData, 1)
For i1 = 1 To UBound(vaSData1, 1)
'MsgBox vaSData(i, 1)
'MsgBox vaSData1(i1, 1)
vaCData(i, 1) = vaSData(i, 1)
vaCData(i, 2) = vaSData1(i1, 1)
Next i1
Next i
Range("f1"
End Sub
------------------------------------------------------------