Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default adding columns to an arrray

How to I load into an array values from a worksheet that are not in a
contiguous range?
For example a 3 column array made up of (from the same row): value in F, sum
of D - G, value in S

--
WinXP - Office2003 (Italian)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default adding columns to an arrray

You could loop through the rows and build your array.
You could pick up each non-contiguous column and build a multi-column array in
your code.
You could pick up the entire range at once and then just ignore the columns you
don't need.

Or you could even pick up each non-contiguous column and use 3 different arrays,
but loop through them in sync.

Here's an example of the first:

Option Explicit
Sub testme()
Dim myArr() As Variant
Dim HowMany As Long
Dim myRng As Range
Dim myCell As Range
Dim wks As Worksheet
Dim rCtr As Long

Set wks = Worksheets("Sheet1")

With wks
'building the array based on column F
Set myRng = .Range("F1", .Cells(.Rows.Count, "F").End(xlUp))
End With

HowMany = myRng.Cells.Count

'how many rows by 3 columns
ReDim myArr(1 To HowMany, 1 To 3)

rCtr = 0
For Each myCell In myRng.Cells
rCtr = rCtr + 1
myArr(rCtr, 1) = myCell.Value
myArr(rCtr, 2) = Application.Sum(myCell.EntireRow.Range("D1:g1"))
myArr(rCtr, 3) = myCell.EntireRow.Range("s1")
Next myCell

'just to show it works
For rCtr = LBound(myArr, 1) To UBound(myArr, 1)
MsgBox myArr(rCtr, 1) & vbLf & myArr(rCtr, 2) & vbLf & myArr(rCtr, 3)
Next rCtr

End Sub

I used Application.Sum(Dx:Gx) to determine the sum. That includes column F. So
if F contains a number, it'll be included in the sum.



David Macdonald wrote:

How to I load into an array values from a worksheet that are not in a
contiguous range?
For example a 3 column array made up of (from the same row): value in F, sum
of D - G, value in S

--
WinXP - Office2003 (Italian)


--

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
Adding Columns, Then deleting old columns May Excel Discussion (Misc queries) 4 October 30th 08 04:44 PM
looking up multiple values in an arrray idaho_bruce Excel Worksheet Functions 5 September 12th 08 04:02 AM
{SUM(IF((ARRRAY FORMULA)} bookman3 Excel Worksheet Functions 8 October 18th 07 04:43 AM
Set a 2D arrray data into a range, given the top-left cell Tom Chau Excel Discussion (Misc queries) 2 June 29th 06 06:53 AM
help with arrray formula Gary Keramidas[_2_] Excel Programming 4 July 13th 05 06:40 AM


All times are GMT +1. The time now is 04:19 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"