strange case of the disappearing array

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(n) = 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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top