filmov
tv
Array redim preserve
Показать описание
기존 배열 자료를 이용하여 확장하는 예제입니다.
This vba code is to expand columns using existing Array.
'---------------------------------
Sub arr_redim_Click()
'---------------------------------
Dim varX As Variant: varX = Range("C8:F13").Value
Dim i As Long
ReDim Preserve varX(1 To UBound(varX, 1), 1 To UBound(varX, 2) + 2)
For i = LBound(varX, 1) To UBound(varX, 1)
If i = 1 Then
varX(i, 4) = "Month": varX(i, 5) = "Day"
varX(i, 6) = "Price"
Else
varX(i, 6) = varX(i, 4)
varX(i, 4) = VBA.Month(varX(i, 3))
varX(i, 5) = VBA.Day(varX(i, 3))
End If
Next i
'paste value
Range("J16").Resize(UBound(varX, 1), UBound(varX, 2)).Value = varX
' set borders
With Range("J16").CurrentRegion
End With
End Sub
#Redim Preserve
#Array
This vba code is to expand columns using existing Array.
'---------------------------------
Sub arr_redim_Click()
'---------------------------------
Dim varX As Variant: varX = Range("C8:F13").Value
Dim i As Long
ReDim Preserve varX(1 To UBound(varX, 1), 1 To UBound(varX, 2) + 2)
For i = LBound(varX, 1) To UBound(varX, 1)
If i = 1 Then
varX(i, 4) = "Month": varX(i, 5) = "Day"
varX(i, 6) = "Price"
Else
varX(i, 6) = varX(i, 4)
varX(i, 4) = VBA.Month(varX(i, 3))
varX(i, 5) = VBA.Day(varX(i, 3))
End If
Next i
'paste value
Range("J16").Resize(UBound(varX, 1), UBound(varX, 2)).Value = varX
' set borders
With Range("J16").CurrentRegion
End With
End Sub
#Redim Preserve
#Array