PC Review


Reply
 
 
needhelp
Guest
Posts: n/a
 
      10th Aug 2009
i'm trying to populate a 2 dimensional array with a value from a cell
(in the first column of the array) and a cell address of a related
cell (in the second column).

I don't know how many values i will have in the array, but i only need
these two pieces of information.

For u = 0 To numrows - t 'cycle through rows in table
If StrConv(Trim(ActiveCell.Offset(u, 0)) & "_" & Trim
(ActiveCell.Offset(u, 1)), vbUpperCase) = ulsheet Then
If StrConv(ActiveCell.Offset(u, 5), vbUpperCase) = "YES" Then
numpks = numpks + 1
ReDim Preserve pkfields(1 To numpks, 1 To 2)
pkfields(numpks, 1) = ActiveCell.Offset(u, 2).Value 'populate
array with value
pkfields(numpks, 2) = ActiveCell.Offset(u, 8).Address 'populate
array with address
End If
End If
Next

I'm getting "subscript out of range" error after the first lot of
values have been put into the array.

Not sure what i'm doing wrong so would appreciate any input.

Cheers
Julie
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      10th Aug 2009
Hi Julie

You can only redim the last dimension of your array, so you have to
swithch row to column like this:

ReDim Preserve pkfields(1 To 2, 1 To numpks)
pkfields(1, numpks) = ActiveCell.Offset(u, 2).Value 'populate
array with value
pkfields(2, numpks) = ActiveCell.Offset(u, 8).Address 'populate
array with address

Hopes this helps.
....
Per

On 10 Aug., 03:36, needhelp <needh...@doubt.com> wrote:
> i'm trying to populate a 2 dimensional array with a value from a cell
> (in the first column of the array) and a cell address of a related
> cell (in the second column).
>
> I don't know how many values i will have in the array, but i only need
> these two pieces of information.
>
> For u = 0 To numrows - t 'cycle through rows in table
> *If StrConv(Trim(ActiveCell.Offset(u, 0)) & "_" & Trim
> (ActiveCell.Offset(u, 1)), vbUpperCase) = ulsheet Then
> * *If StrConv(ActiveCell.Offset(u, 5), vbUpperCase) = "YES" Then
> * * *numpks = numpks + 1
> ReDim Preserve pkfields(1 To numpks, 1 To 2)
> * * *pkfields(numpks, 1) = ActiveCell.Offset(u, 2).Value 'populate
> array with value
> * * *pkfields(numpks, 2) = ActiveCell.Offset(u, 8).Address 'populate
> array with address
> * *End If
> * End If
> Next
>
> I'm getting "subscript out of range" error after the first lot of
> values have been put into the array.
>
> Not sure what i'm doing wrong so would appreciate any input.
>
> Cheers
> Julie


 
Reply With Quote
 
needhelp
Guest
Posts: n/a
 
      10th Aug 2009
thanks Par .. knowing that helps

It works now.

Cheers
Julie
 
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
Prevent cell/array references from changing when altering/moving thecell/array nme Microsoft Excel Misc 1 19th Sep 2008 01:53 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
Pass from C# (framework 1.1) array of delegates to unmanaged DLL as array of function pointers verpeter@gmail.com Microsoft C# .NET 0 23rd Aug 2006 02:20 PM
select variables ranges, copy to array, paste the array in new workbook Mathew Microsoft Excel Worksheet Functions 1 1st Apr 2005 09:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:35 PM.