PC Review


Reply
Thread Tools Rate Thread

another array approach question

 
 
Gary Keramidas
Guest
Posts: n/a
 
      24th Apr 2007
let's see if i can explain clearly.

i'm using this to initialize the array
ReDim arr(0 To 1, 0 To 0)

then i use a redim preserve to add the elements

how can i tell how many elements there are to loop through?

ubound(arr) returns 1 and i know there are more elements than that.


--


Gary



 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      24th Apr 2007
To find the number of "rows"
msgbox ubound(arr,1) - lbound(arr,1) + 1

To find the number of "columns" in that array:
msgbox ubound(arr,2) - lbound(arr,2) + 1

If you want the total elements, just multiply these two.



Gary Keramidas wrote:
>
> let's see if i can explain clearly.
>
> i'm using this to initialize the array
> ReDim arr(0 To 1, 0 To 0)
>
> then i use a redim preserve to add the elements
>
> how can i tell how many elements there are to loop through?
>
> ubound(arr) returns 1 and i know there are more elements than that.
>
> --
>
> Gary


--

Dave Peterson
 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      24th Apr 2007
Hi Gary,

Try:

Debug.Print "UBound(arr, 1) = "; UBound(arr, 1), _
"UBound(arr, 2) = "; UBound(arr, 2)



---
Regards,
Norman


"Gary Keramidas" <GKeramidasATmsn.com> wrote in message
news:(E-Mail Removed)...
> let's see if i can explain clearly.
>
> i'm using this to initialize the array
> ReDim arr(0 To 1, 0 To 0)
>
> then i use a redim preserve to add the elements
>
> how can i tell how many elements there are to loop through?
>
> ubound(arr) returns 1 and i know there are more elements than that.
>
>
> --
>
>
> Gary
>
>
>



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      24th Apr 2007
thanks dave

--


Gary


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> To find the number of "rows"
> msgbox ubound(arr,1) - lbound(arr,1) + 1
>
> To find the number of "columns" in that array:
> msgbox ubound(arr,2) - lbound(arr,2) + 1
>
> If you want the total elements, just multiply these two.
>
>
>
> Gary Keramidas wrote:
>>
>> let's see if i can explain clearly.
>>
>> i'm using this to initialize the array
>> ReDim arr(0 To 1, 0 To 0)
>>
>> then i use a redim preserve to add the elements
>>
>> how can i tell how many elements there are to loop through?
>>
>> ubound(arr) returns 1 and i know there are more elements than that.
>>
>> --
>>
>> Gary

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      24th Apr 2007
thanks again norman

--


Gary


"Norman Jones" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Gary,
>
> Try:
>
> Debug.Print "UBound(arr, 1) = "; UBound(arr, 1), _
> "UBound(arr, 2) = "; UBound(arr, 2)
>
>
>
> ---
> Regards,
> Norman
>
>
> "Gary Keramidas" <GKeramidasATmsn.com> wrote in message
> news:(E-Mail Removed)...
>> let's see if i can explain clearly.
>>
>> i'm using this to initialize the array
>> ReDim arr(0 To 1, 0 To 0)
>>
>> then i use a redim preserve to add the elements
>>
>> how can i tell how many elements there are to loop through?
>>
>> ubound(arr) returns 1 and i know there are more elements than that.
>>
>>
>> --
>>
>>
>> Gary
>>
>>
>>

>
>



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      24th Apr 2007
just curious, is something like this possible?

arr = Range("d2:d21,f2:f21")


--


Gary


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> To find the number of "rows"
> msgbox ubound(arr,1) - lbound(arr,1) + 1
>
> To find the number of "columns" in that array:
> msgbox ubound(arr,2) - lbound(arr,2) + 1
>
> If you want the total elements, just multiply these two.
>
>
>
> Gary Keramidas wrote:
>>
>> let's see if i can explain clearly.
>>
>> i'm using this to initialize the array
>> ReDim arr(0 To 1, 0 To 0)
>>
>> then i use a redim preserve to add the elements
>>
>> how can i tell how many elements there are to loop through?
>>
>> ubound(arr) returns 1 and i know there are more elements than that.
>>
>> --
>>
>> Gary

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Apr 2007
Is it possible? Yes.
Does it work the way you want? I bet not.

It'll pick up the values in the first area and plop them into the array.

But you should try it and see.

Gary Keramidas wrote:
>
> just curious, is something like this possible?
>
> arr = Range("d2:d21,f2:f21")
>
> --
>
> Gary
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > To find the number of "rows"
> > msgbox ubound(arr,1) - lbound(arr,1) + 1
> >
> > To find the number of "columns" in that array:
> > msgbox ubound(arr,2) - lbound(arr,2) + 1
> >
> > If you want the total elements, just multiply these two.
> >
> >
> >
> > Gary Keramidas wrote:
> >>
> >> let's see if i can explain clearly.
> >>
> >> i'm using this to initialize the array
> >> ReDim arr(0 To 1, 0 To 0)
> >>
> >> then i use a redim preserve to add the elements
> >>
> >> how can i tell how many elements there are to loop through?
> >>
> >> ubound(arr) returns 1 and i know there are more elements than that.
> >>
> >> --
> >>
> >> Gary

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      25th Apr 2007
you're right, it probably won't. i was wondering how to get the values from
column f from the array and couldn't.

--


Gary


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is it possible? Yes.
> Does it work the way you want? I bet not.
>
> It'll pick up the values in the first area and plop them into the array.
>
> But you should try it and see.
>
> Gary Keramidas wrote:
>>
>> just curious, is something like this possible?
>>
>> arr = Range("d2:d21,f2:f21")
>>
>> --
>>
>> Gary
>>
>> "Dave Peterson" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > To find the number of "rows"
>> > msgbox ubound(arr,1) - lbound(arr,1) + 1
>> >
>> > To find the number of "columns" in that array:
>> > msgbox ubound(arr,2) - lbound(arr,2) + 1
>> >
>> > If you want the total elements, just multiply these two.
>> >
>> >
>> >
>> > Gary Keramidas wrote:
>> >>
>> >> let's see if i can explain clearly.
>> >>
>> >> i'm using this to initialize the array
>> >> ReDim arr(0 To 1, 0 To 0)
>> >>
>> >> then i use a redim preserve to add the elements
>> >>
>> >> how can i tell how many elements there are to loop through?
>> >>
>> >> ubound(arr) returns 1 and i know there are more elements than that.
>> >>
>> >> --
>> >>
>> >> Gary
>> >
>> > --
>> >
>> > Dave Peterson

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Apr 2007
You could loop through the range:

Option Explicit
Sub testme()

Dim myArr() As Variant
Dim myRng As Range
Dim myCell As Range
Dim iRow As Long

With ActiveSheet
Set myRng = .Range("d2:d21")
End With

ReDim myArr(1 To myRng.Rows.Count, 1 To 2)
iRow = 0
For Each myCell In myRng.Cells
iRow = iRow + 1
myArr(iRow, 1) = myCell.Value
myArr(iRow, 2) = myCell.Offset(0, 2).Value
Next myCell

End Sub


Gary Keramidas wrote:
>
> you're right, it probably won't. i was wondering how to get the values from
> column f from the array and couldn't.
>
> --
>
> Gary
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Is it possible? Yes.
> > Does it work the way you want? I bet not.
> >
> > It'll pick up the values in the first area and plop them into the array.
> >
> > But you should try it and see.
> >
> > Gary Keramidas wrote:
> >>
> >> just curious, is something like this possible?
> >>
> >> arr = Range("d2:d21,f2:f21")
> >>
> >> --
> >>
> >> Gary
> >>
> >> "Dave Peterson" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > To find the number of "rows"
> >> > msgbox ubound(arr,1) - lbound(arr,1) + 1
> >> >
> >> > To find the number of "columns" in that array:
> >> > msgbox ubound(arr,2) - lbound(arr,2) + 1
> >> >
> >> > If you want the total elements, just multiply these two.
> >> >
> >> >
> >> >
> >> > Gary Keramidas wrote:
> >> >>
> >> >> let's see if i can explain clearly.
> >> >>
> >> >> i'm using this to initialize the array
> >> >> ReDim arr(0 To 1, 0 To 0)
> >> >>
> >> >> then i use a redim preserve to add the elements
> >> >>
> >> >> how can i tell how many elements there are to loop through?
> >> >>
> >> >> ubound(arr) returns 1 and i know there are more elements than that.
> >> >>
> >> >> --
> >> >>
> >> >> Gary
> >> >
> >> > --
> >> >
> >> > Dave Peterson

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      25th Apr 2007
thanks dave, i have code that works, i was just wondering about the technique i
posted.

i think i may have even adapted some of your code:

ReDim arr(0 To 1, 0 To 0)
For q = 12 To lRowIng
If .Cells(q, "B").Value <> "" Then
ReDim Preserve arr(0 To 1, 0 To arraySize)
arr(0, arraySize) = .Cells(q, "B").Value
arr(1, arraySize) = .Cells(q, "F").Value
arraySize = arraySize + 1
End If
Next

--


Gary


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You could loop through the range:
>
> Option Explicit
> Sub testme()
>
> Dim myArr() As Variant
> Dim myRng As Range
> Dim myCell As Range
> Dim iRow As Long
>
> With ActiveSheet
> Set myRng = .Range("d2:d21")
> End With
>
> ReDim myArr(1 To myRng.Rows.Count, 1 To 2)
> iRow = 0
> For Each myCell In myRng.Cells
> iRow = iRow + 1
> myArr(iRow, 1) = myCell.Value
> myArr(iRow, 2) = myCell.Offset(0, 2).Value
> Next myCell
>
> End Sub
>
>
> Gary Keramidas wrote:
>>
>> you're right, it probably won't. i was wondering how to get the values from
>> column f from the array and couldn't.
>>
>> --
>>
>> Gary
>>
>> "Dave Peterson" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Is it possible? Yes.
>> > Does it work the way you want? I bet not.
>> >
>> > It'll pick up the values in the first area and plop them into the array.
>> >
>> > But you should try it and see.
>> >
>> > Gary Keramidas wrote:
>> >>
>> >> just curious, is something like this possible?
>> >>
>> >> arr = Range("d2:d21,f2:f21")
>> >>
>> >> --
>> >>
>> >> Gary
>> >>
>> >> "Dave Peterson" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> > To find the number of "rows"
>> >> > msgbox ubound(arr,1) - lbound(arr,1) + 1
>> >> >
>> >> > To find the number of "columns" in that array:
>> >> > msgbox ubound(arr,2) - lbound(arr,2) + 1
>> >> >
>> >> > If you want the total elements, just multiply these two.
>> >> >
>> >> >
>> >> >
>> >> > Gary Keramidas wrote:
>> >> >>
>> >> >> let's see if i can explain clearly.
>> >> >>
>> >> >> i'm using this to initialize the array
>> >> >> ReDim arr(0 To 1, 0 To 0)
>> >> >>
>> >> >> then i use a redim preserve to add the elements
>> >> >>
>> >> >> how can i tell how many elements there are to loop through?
>> >> >>
>> >> >> ubound(arr) returns 1 and i know there are more elements than that.
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Gary
>> >> >
>> >> > --
>> >> >
>> >> > Dave Peterson
>> >
>> > --
>> >
>> > Dave Peterson

>
> --
>
> Dave Peterson



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula/Approach Question =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 1 9th Nov 2007 04:47 PM
VBA Question - Is there a better approach? =?Utf-8?B?U2NvdHQgV2FnbmVy?= Microsoft Excel Programming 4 3rd Apr 2006 07:51 PM
Design approach question Darryl Microsoft Access Forms 3 25th Oct 2005 07:40 PM
Style/Approach Question CJM Microsoft ASP .NET 2 14th Aug 2004 04:11 AM
Coding Approach Question... Beringer Microsoft C# .NET 1 12th May 2004 05:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:59 AM.