LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Stupid array question

Can someone please point out what is wrong with the following:

Sub Test()
Dim asdf() As Integer, i As Integer
For i = 0 To 5
asdf(i) = i
Next i
End Sub

doesn't work even if Option Base 0 were to be included, though
obviously isn't relevant to my problem

Whereas it likes:

Sub Test_()
Dim asdf(0 To 5) As Integer, i As Integer
For i = 0 To 5
asdf(i) = i
Next i
End Sub

what i'd actually like to do is loop through a named range, and assign
to the array only cells that meet a certain criteria, and join those
values to output to another cell i.e.

Sub Test()

'Two worksheets on workbook, as in default
'Sheet1 contains has a named range, "MyNamedRange", 3 by 1 in size
'cell A1 has text "apple"
'cell A2 is blank
'cell A3 has text "banana"

Dim asdf() As String, i As Integer, arr_size As Integer

arr_size = 0

For i = 0 To 2 'the named is range is 5x1, say a1:a5
'If
Len(Workbooks("Book1").Sheet1.Range("mynamedrange" ).Cells(i, 1).Value)
1 Then

If Len(Sheet1.Range("mynamedrange").Cells(i + 1).Value) 0
Then
asdf(arr_size) = Sheet1.Range("MyNamedRange").Cells(i +
1).Value
arr_size = arr_size + 1
End If
Next i

' would like array to be ("apple", "banana", "") at this point
' and at this point arr_size = 2

ReDim Preserve asdf(0 To arr_size - 1) 'resize

Worksheets("Sheet2").Cells(5, 5).Value = Join(asdf, ", ") & "."

End Sub

note this sub doesn't actually work, to run it, replace:
"Dim asdf() As String" with "Dim asdf(0 to 2) As String"
and comment the Redim Preserve line as array has been dimensioned.

This is really bugging me, and i know it's something stupid but just
can't see it!

Thanks in advance
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
big stupid question Wu Excel Discussion (Misc queries) 4 May 17th 08 05:33 PM
Probably a Stupid Question Paige Excel Discussion (Misc queries) 10 February 4th 08 06:52 PM
Stupid question [email protected] Excel Programming 3 July 13th 07 07:45 PM
stupid question Kimberly New Users to Excel 4 May 18th 07 08:55 PM
Stupid, stupid question.... DS Excel Programming 3 September 25th 05 03:51 PM


All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"