Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Specifying a range within an array

Can someone kindly tell me how to specify a range within a 2-dimensional
array (e.g., row 1, column 1 through row 1, column 14)? I'm trying to do so
in the following VBA line:

RowHourCellsFound = WorksheetFunction.CountIf(Range(HoursArray(1, 1) & _
":" & HoursArray(1, 14)), "0")

Thanks in advance for any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Specifying a range within an array

k = 0
For i = 1 To 1: For j = 1 To 14
If HoursArray(i, j) 0 Then k = k + 1
Next: Next
RowHourCellsFound = k

Or, assuming that the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

RowHourCellsFound = ArrayCountIf(SubArray(HoursArray,1,14,1,1),0,"")

Alan Beban

Bob wrote:
Can someone kindly tell me how to specify a range within a 2-dimensional
array (e.g., row 1, column 1 through row 1, column 14)? I'm trying to do so
in the following VBA line:

RowHourCellsFound = WorksheetFunction.CountIf(Range(HoursArray(1, 1) & _
":" & HoursArray(1, 14)), "0")

Thanks in advance for any help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Specifying a range within an array

Alan,
Thanks for your help! Although your response is specific to my current
problem, for my own edification and for future reference, is there a
"generic" way to specify a range of "cells" in an array?
Thanks again,
Bob


"Alan Beban" wrote:

k = 0
For i = 1 To 1: For j = 1 To 14
If HoursArray(i, j) 0 Then k = k + 1
Next: Next
RowHourCellsFound = k

Or, assuming that the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

RowHourCellsFound = ArrayCountIf(SubArray(HoursArray,1,14,1,1),0,"")

Alan Beban

Bob wrote:
Can someone kindly tell me how to specify a range within a 2-dimensional
array (e.g., row 1, column 1 through row 1, column 14)? I'm trying to do so
in the following VBA line:

RowHourCellsFound = WorksheetFunction.CountIf(Range(HoursArray(1, 1) & _
":" & HoursArray(1, 14)), "0")

Thanks in advance for any help.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Specifying a range within an array

For a "range of cells", as you call it, in e.g., myArray

For i = startRow to endRow:For j = startColumn to endColumn
RangeOfCells(i, j) = myArray(i, j)
Next:Next

Using the downloaded functions it's implicit in the response below
(i.e., SubArray(HoursArray,1,14,1,1)). Review the description of the
downloaded SubArray function.

SubArray(myArray, startColumn, endColumn, startRow, endRow)

to return a 1-based "range of cells" (i.e., subarray).

The built-in COUNTIF function doesn't operate on VBA arrays, hence the
use of the downloaded ArrayCountIf function below.

Alan Beban

Bob wrote:
Alan,
Thanks for your help! Although your response is specific to my current
problem, for my own edification and for future reference, is there a
"generic" way to specify a range of "cells" in an array?
Thanks again,
Bob


"Alan Beban" wrote:
k = 0
For i = 1 To 1: For j = 1 To 14
If HoursArray(i, j) 0 Then k = k + 1
Next: Next
RowHourCellsFound = k

Or, assuming that the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

RowHourCellsFound = ArrayCountIf(SubArray(HoursArray,1,14,1,1),0,"")

Alan Beban

  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Specifying a range within an array

Alan,
As always, thanks!
I will definitely take a closer look at your SubArray function. In
hindsight, if there was a simpler or more direct way to address a range
within an array, you wouldn't have needed to write a UDF. Silly me.
Thanks again,
Bob


"Alan Beban" wrote:

For a "range of cells", as you call it, in e.g., myArray

For i = startRow to endRow:For j = startColumn to endColumn
RangeOfCells(i, j) = myArray(i, j)
Next:Next

Using the downloaded functions it's implicit in the response below
(i.e., SubArray(HoursArray,1,14,1,1)). Review the description of the
downloaded SubArray function.

SubArray(myArray, startColumn, endColumn, startRow, endRow)

to return a 1-based "range of cells" (i.e., subarray).

The built-in COUNTIF function doesn't operate on VBA arrays, hence the
use of the downloaded ArrayCountIf function below.

Alan Beban

Bob wrote:
Alan,
Thanks for your help! Although your response is specific to my current
problem, for my own edification and for future reference, is there a
"generic" way to specify a range of "cells" in an array?
Thanks again,
Bob


"Alan Beban" wrote:
k = 0
For i = 1 To 1: For j = 1 To 14
If HoursArray(i, j) 0 Then k = k + 1
Next: Next
RowHourCellsFound = k

Or, assuming that the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

RowHourCellsFound = ArrayCountIf(SubArray(HoursArray,1,14,1,1),0,"")

Alan Beban




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Specifying a range within an array

Well, I suppose it's fair to say that some might think

For i = startRow to endRow:For j = startColumn to endColumn
RangeOfCells(i, j) = myArray(i, j)
Next:Next

is simpler and more direct. For someone like me, who always has the
downloaded functions available, perhaps not.

Alan Beban

Bob wrote:
Alan,
As always, thanks!
I will definitely take a closer look at your SubArray function. In
hindsight, if there was a simpler or more direct way to address a range
within an array, you wouldn't have needed to write a UDF. Silly me.
Thanks again,
Bob


"Alan Beban" wrote:


For a "range of cells", as you call it, in e.g., myArray

For i = startRow to endRow:For j = startColumn to endColumn
RangeOfCells(i, j) = myArray(i, j)
Next:Next

Using the downloaded functions it's implicit in the response below
(i.e., SubArray(HoursArray,1,14,1,1)). Review the description of the
downloaded SubArray function.

SubArray(myArray, startColumn, endColumn, startRow, endRow)

to return a 1-based "range of cells" (i.e., subarray).

The built-in COUNTIF function doesn't operate on VBA arrays, hence the
use of the downloaded ArrayCountIf function below.

Alan Beban

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
How to fix an array or range delboy Excel Discussion (Misc queries) 1 February 12th 08 08:14 PM
Range to Array Gary''s Student Excel Programming 5 June 7th 07 09:22 PM
copy one array formula to an array range guedj54 Excel Programming 2 October 29th 06 07:38 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Excel Programming 0 July 27th 05 03:59 PM
Range as array J.E. McGimpsey Excel Programming 1 September 10th 03 11:06 PM


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