PDA

View Full Version : erase array value partially



samisamih
05-21-2015, 06:59 AM
i want to erase the value from the array partially (not to reset all the array )
the code


Sub m()
Dim arr(1 To 10) As Integer
For i = 1 To 10
arr(i) = i
Next i
Erase arr(1 to 9) - ErrOr
Cells(1, 2).Resize(UBound(arr)).Value = Application.Transpose(arr)
End Sub


in the above code i wrote: erase arr(1 to 9),"the indexes that i want to reset again" and i want the last index : arr(10) not be reset again, is there a way to do this

thanks

Paul_Hossler
05-21-2015, 08:29 AM
Not sure what you want to end up with, but this will enter 1 -10 in the first column, and 9 blanks and 10 in the third

I used an array of variants, since an Empty Integer shows as 0





Option Explicit
Sub m()
Dim i As Long
Dim arr(1 To 10) As Variant

For i = 1 To 10
arr(i) = i
Next I
ActiveSheet.Cells(1, 1).Resize(UBound(arr), 1).Value = Application.Transpose(arr)

For i = 1 To 9
arr(i) = Empty
Next I
ActiveSheet.Cells(1, 3).Resize(UBound(arr), 1).Value = Application.Transpose(arr)

End Sub



13463