View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default RANGES AND DYNAMIC ARRAYS!!


Okay, for your second question, this code will create a one-dimensional
String array (which I named SnakedArray in my code) containing your data in
snaked order (all of Column B's data followed by all of Column D's data,
etc.)...

Dim R As Range
Dim X As Long
Dim LastRow As Long
Dim ColData As String
Dim ColumnArray() As String
Dim SnakedArray() As String
Const StartRow As Long = 1
Const Cols As String = "B D F H"
ColumnArray = Split(Cols)
For X = 0 To 3
Set R = Range(ColumnArray(X) & StartRow & ":" & ColumnArray(X) & _
Cells(Rows.Count, ColumnArray(X)).End(xlUp).Row)
If X Then ColData = ColData & Chr(1)
If R.Count = 1 Then
If R.Value < "" Then
ColData = ColData & R.Value
Else
ColData = Left(ColData, Len(ColData) - 1)
End If
Else
ColData = ColData & Join(WorksheetFunction.Transpose(R), Chr(1))
End If
Next
SnakedArray = Split(ColData, Chr(1))

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
I'm answering this during a short "break" time with the company I have
over this morning, so this is not a complete answer yet (they are leaving
soon, so I'll get to the second part shortly). This is my response to the
first part...

Dim LastCell As Range
Dim LastCellValue As Variant
Dim LastCellAddress As String
Set LastCell = Range("B:B,D:D,F:F,H:H").Find(What:="*", _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
LastCellAddress = LastCell.Address(0, 0)
LastCellValue = LastCell.Value
'
' Show that it worked
'
MsgBox "Address = " & LastCellAddress & vbLf & "Value = " & LastCellValue

--
Rick (MVP - Excel)


"jay dean" wrote in message
...
Hi Rick - Here is the clarification:

(1) The amount of data in the range is not constant. Therefore, the
"last cell" filled could be in the "right-most" column, or the column
next to the "right-most" or the column 2nd next to the "right-most"
column, and so on. The direction of the data is this way: "Fill the
"left-most" column B:B (from top-down), then continue in the next
"left-most" column D:D (from the top-down),then continue in the next
"left-most" column F:F (from the top-down), and so on..

(2) The type of array I am looking to end up with is either a (1 row by
N columns) OR (N rows by 1 column)., where N is the number of cells
containing data in the "snake-like" range structure.. (that is, starting
from B1 to B65536, then continuing from D1 (acting as the 65537th cell)
through D65536 (acting as cell 2*65536), then continuing in F1 through
F65536, and so on.

I hope this clears it up.
Thanks
Jay

*** Sent via Developersdex http://www.developersdex.com ***