Skip to content

Instantly share code, notes, and snippets.

@nobrinskii
Created March 16, 2012 05:29
Show Gist options
  • Save nobrinskii/2048662 to your computer and use it in GitHub Desktop.
Save nobrinskii/2048662 to your computer and use it in GitHub Desktop.
[vba/excel] 配列の新しいインデックス番号を返す
'------------------------------------------------------------------------------
'配列の新しいインデックス番号を返す
'------------------------------------------------------------------------------
'【引数】配列(あるいはEmpty値のVariant型)
'【戻り値】long型
'【備考】引数が配列ではないく、かつ初期化済みの場合は-1を返す。
Private Function SetNewIndex(varArray As Variant) As Long
Dim lngNewIndex As Long
Dim index As Long
If IsEmpty(varArray) Then
ReDim varArray(0)
lngNewIndex = 0
ElseIf Not IsArray(varArray) Then
lngNewIndex = -1
Else
index = UBound(varArray)
lngNewIndex = index + 1
If lngNewIndex = 0 Then
ReDim varArray(0)
Else
ReDim Preserve varArray(lngNewIndex)
End If
End If
SetNewIndex = lngNewIndex
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment