switters_aka
Board Regular
- Joined
- Oct 26, 2010
- Messages
- 118
Would be grateful for help here, although I know I am doing something stupid but I can't figure it out. I am populating an array budline() with values from a worksheet that meet certain criteria. During the for loop I am returning the array values to a column in the same worksheet but this is just a test to prove the array values are there. However, when I try and call an array value at the end of the sub, it appears to be empty. Any help would be gratefully received.
Sub addvoucher()
Dim countrows As Integer
Dim len1, len2, len3, n, i, HdrRow, LastRow As Integer
Dim budline() As Variant
Dim len1str, len2str As String
Dim ctr As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
HdrRow = Application.Sheets("Budget Summary ENG").Range("A:A").Find("*").Row
LastRow = LastCell(Sheet3).Row + 1
i = HdrRow + 1
n = 1
'MsgBox i & "to" & LastRow
'Exit Sub
For i = 1 To LastRow
len1str = Range("A" & i)
len2str = Replace(len1str, ".", "")
len1 = Len(len1str)
len2 = Len(len2str)
len3 = len1 - len2
If len3 = 4 Then
ReDim budline(1 To n)
budline = len1str
n = n + 1
Range("i" & n) = budline(n - 1) 'proof that the array was populated once upon a time.
Else
End If
Next i
'ReDim budline(1 To n - 1)
'For ctr = LBound(budline) To UBound(budline)
'UserForm1.ListBox1.AddItem budline(ctr)
'Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
'proof that the array is populated - it seems not to be.
MsgBox budline(1)
UserForm1.Show
End Sub
Sub addvoucher()
Dim countrows As Integer
Dim len1, len2, len3, n, i, HdrRow, LastRow As Integer
Dim budline() As Variant
Dim len1str, len2str As String
Dim ctr As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
HdrRow = Application.Sheets("Budget Summary ENG").Range("A:A").Find("*").Row
LastRow = LastCell(Sheet3).Row + 1
i = HdrRow + 1
n = 1
'MsgBox i & "to" & LastRow
'Exit Sub
For i = 1 To LastRow
len1str = Range("A" & i)
len2str = Replace(len1str, ".", "")
len1 = Len(len1str)
len2 = Len(len2str)
len3 = len1 - len2
If len3 = 4 Then
ReDim budline(1 To n)
budline = len1str
n = n + 1
Range("i" & n) = budline(n - 1) 'proof that the array was populated once upon a time.
Else
End If
Next i
'ReDim budline(1 To n - 1)
'For ctr = LBound(budline) To UBound(budline)
'UserForm1.ListBox1.AddItem budline(ctr)
'Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
'proof that the array is populated - it seems not to be.
MsgBox budline(1)
UserForm1.Show
End Sub