Dynamic Array to string

PanzerRanger

New Member
Joined
Jan 3, 2018
Messages
20
Why does the debug.printout generate an error (run time 5: Invalid procedure call or argument)? If I print a single item in the array it works. If I use a static array the debug.print works. Also is there a solution to get the printout to show as date, it now prints f.e. 42837 instead of 2017-04-12

Sub test()
Dim nr, a, c As Integer, ary() As Long, info As String, dat as date
lrnr = Blad1.Range("A" & Rows.Count).End(xlUp).Row
nr = lrnr - 25 'Read lrnr as 38
a = 1
c = 26

ReDim ary(a To nr)


Do
dat = Range("A" & c).Value
ary(a) = dat
c = c + 1
a = a + 1
Loop Until c > lrnr


info = Join(ary, vbnewline)
Debug.Print info

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
NO!!! Declare ary as date array:
Dim ary() as Date
Why do you all sooo like ugly and slow variant type?

By the way, your declaration
Dim nr, a, c As Integer
means
Dim nr As Variant, a As Variant, c As Integer
You must write
Dim nr As Integer, a As Integer, c As Integer
or better
Dim nr%, a%, c%

And working with integers is not good idea when you need longs! Hence
Dim nr&, a&, c&
is best.


<strike></strike>
 
Upvote 0
Jan,

Are you a very strict headmistress on the side.

We are all at various stages of learning here, some better than others, when I code for someone, no one gets angry at what I put, they (often) suggest better coding.

It's then for me to read that code and then learn from if it if I wish. Which I do.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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