Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Populate Array

Is it possible to populate an array from a column of data which has gaps in
it and have the array filled only with data?
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Populate Array

There are probably more elegant ways of doing it, but you could populate an
array like this (change the first set statement to whatever range you need -
I am using ColumnA on Sheet1 (note this is the codename) for my example)

Sub Test()
Dim Data() As Variant
Dim i As Long
Dim Count As Long
Dim Isect As Range

Set Isect = Application.Intersect(Sheet1.UsedRange, _
Sheet1.Columns(1))

ReDim Data(1 To Isect.Cells.Count)

For i = 1 To Isect.Cells.Count
If Not IsEmpty(Isect.Cells(i)) Then
Count = Count + 1
Data(Count) = Isect.Cells(i).Value
End If
Next i

ReDim Preserve Data(1 To Count)

For i = LBound(Data) To UBound(Data)
MsgBox Data(i)
Next i

End Sub


Or, if you wanted to work with the range directly and not use an array you
could use this (or something similar):

Sub Test2()
Dim Isect As Range
Dim VisibleCells As Range
Dim x As Range

Set Isect = Application.Intersect(Sheet1.UsedRange, _
Sheet1.Columns(1))

Isect.SpecialCells(xlCellTypeBlanks).EntireRow.Hid den = True
Set VisibleCells = Isect.SpecialCells(xlCellTypeVisible)
Isect.EntireRow.Hidden = False

For Each x In VisibleCells
MsgBox x.Value
Next x

End Sub

"Dale" wrote:

Is it possible to populate an array from a column of data which has gaps in
it and have the array filled only with data?

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
Array to Populate ListBox Problem pallaver Excel Discussion (Misc queries) 1 July 25th 08 08:50 AM
Populate an array that is a subset of a larger array? Jeff Excel Worksheet Functions 1 September 25th 07 12:51 AM
populate array Marina Limeira Excel Programming 3 January 20th 06 05:55 PM
populate chart array John Excel Programming 2 February 19th 04 04:46 AM
Populate array Beto[_3_] Excel Programming 6 December 30th 03 09:53 PM


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