Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default another array approach question

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default another array approach question

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default another array approach question

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
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default another array approach question

thanks dave

--


Gary


"Dave Peterson" wrote in message
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default another array approach question

thanks again norman

--


Gary


"Norman Jones" wrote in message
...
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
...
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









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default another array approach question

just curious, is something like this possible?

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


--


Gary


"Dave Peterson" wrote in message
...
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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default another array approach question

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" wrote in message
...
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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default another array approach question

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" wrote in message
...
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" wrote in message
...
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



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default another array approach question

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" wrote in message
...
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" wrote in message
...
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
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default another array approach question

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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default another array approach question

If the functions in the file at http:/home.pacbell.net/beban are
available to your workbook, you might consider

lrow = 17
arr = ArrayReshape(MakeArray(Range("D12:D" & lrow), Range("F12:F" &
lrow), 1), 2, lrow - 12 + 1)

Alan Beban

Gary Keramidas wrote:
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

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default another array approach question

Here's something quick-n-dirty...

Sub Example()
Dim Arr
Arr = T2(Array(T1([D2:D21]), T1([F2:F21])))
End Sub


'// Common Library Functions...

Function T1(v)
' Transpose 1 time.
With WorksheetFunction
T1 = .Transpose(v)
End With
End Function

Function T2(v)
' Double Transpose.
With WorksheetFunction
T2 = .Transpose(.Transpose(v))
End With
End Function

--
HTH :)
Dana DeLouis
Windows XP & Office 2007


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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
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
Formula/Approach Question carl Excel Worksheet Functions 1 November 9th 07 04:47 PM
What is the right approach? Epinn Excel Worksheet Functions 3 October 8th 06 12:22 PM
VBA Question - Is there a better approach? Scott Wagner Excel Programming 4 April 3rd 06 07:51 PM
How to approach this? mevetts Excel Discussion (Misc queries) 1 January 10th 06 04:20 PM
New approach davegb Excel Programming 6 December 6th 05 04:31 PM


All times are GMT +1. The time now is 02:12 AM.

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

About Us

"It's about Microsoft Excel"