Question : Arrays in Excel macro

Could you let me know why I get a "script out of range" error for the following code snippet? Thanks.

Dim NormalTime As Integer
Dim DateCount As Integer
Dim TaskCount As Integer
Dim NonBlankHolder() As Integer
Dim Counter1 As Integer
Dim Counter2 As Integer

Counter2 = 0

NormalTime = WorksheetFunction.Sum(ActiveSheet.Range("C2:C5000"))
DateCount = WorksheetFunction.Count(ActiveSheet.Range("A2:A5000"))
TaskCount = WorksheetFunction.CountA(ActiveSheet.Range("B2:B5000"))

For Counter1 = 2 To TaskCount
  If (ActiveSheet.Cells(TaskCount, 1) <> "") Then
  NonBlankHolder(0) = 1
  Counter2 = Counter2 + 1
  End If
Next Counter1


End Sub

Answer : Arrays in Excel macro

You need to put a value in the array when you define it otherwise you can't add values to it.

So, instead of:
Dim NonBlankHolder() As Integer

use:
Dim NonBlankHolder(0) As Integer

Random Solutions  
 
programming4us programming4us