Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy Data From Cells To Array

In my sheet, I have a range of data like this...

Class Total
500 20.0
500 12.0
500 35.5
502 28.3
502 13.7
503 19.3
504 21.4
504 30.7
504 14.5
....

In VBA, I need to copy the classes to an array, but with no duplicate.
I mean 500, 502, 503 and 504. How can I do that? Thank you in advance.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200603/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Copy Data From Cells To Array

Something like this...
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'----------
Sub GetStarted()
Call NoEvilTwins(Selection)
End Sub
'----------

Function NoEvilTwins(ByRef rngArea As Excel.Range)
'Jim Cone - San Francisco, USA - March 07, 2006
Dim colScreener As VBA.Collection
Dim varArray() As Variant
Dim rngCell As Excel.Range
Dim lngC As Long
Dim lngR As Long

Set colScreener = New VBA.Collection
ReDim varArray(1 To rngArea.Rows.Count, 1 To rngArea.Columns.Count)
lngR = 1

For Each rngCell In rngArea.Columns(1).Cells
On Error Resume Next
colScreener.Add rngCell.Value, CStr(rngCell.Value)
If Err.Number = 0 Then
On Error GoTo 0
'Load the array
For lngC = 1 To rngArea.Columns.Count
varArray(lngR, lngC) = rngCell(1, lngC).Value
Next
lngR = lngR + 1
Else
Err.Clear
On Error GoTo 0
End If
Next

'Pick a place to put it.
'If there were duplicates then the array will have empty elements.
Range("A1").Resize(colScreener.Count, rngArea.Columns.Count).Value = varArray

Set colScreener = Nothing
End Function
'----------


"MarcL via OfficeKB.com" <u19204@uwe wrote in message
In my sheet, I have a range of data like this...
Class Total
500 20.0
500 12.0
500 35.5
502 28.3
502 13.7
503 19.3
504 21.4
504 30.7
504 14.5
In VBA, I need to copy the classes to an array, but with no duplicate.
I mean 500, 502, 503 and 504. How can I do that? Thank you in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy Data From Cells To Array

Thank you Jim. But I am astonished that there is no function in Excel that
could do that... like filter advanced combined with copytoarray function.

Jim Cone wrote:
Something like this...
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'----------
Sub GetStarted()
Call NoEvilTwins(Selection)
End Sub
'----------

Function NoEvilTwins(ByRef rngArea As Excel.Range)
'Jim Cone - San Francisco, USA - March 07, 2006
Dim colScreener As VBA.Collection
Dim varArray() As Variant
Dim rngCell As Excel.Range
Dim lngC As Long
Dim lngR As Long

Set colScreener = New VBA.Collection
ReDim varArray(1 To rngArea.Rows.Count, 1 To rngArea.Columns.Count)
lngR = 1

For Each rngCell In rngArea.Columns(1).Cells
On Error Resume Next
colScreener.Add rngCell.Value, CStr(rngCell.Value)
If Err.Number = 0 Then
On Error GoTo 0
'Load the array
For lngC = 1 To rngArea.Columns.Count
varArray(lngR, lngC) = rngCell(1, lngC).Value
Next
lngR = lngR + 1
Else
Err.Clear
On Error GoTo 0
End If
Next

'Pick a place to put it.
'If there were duplicates then the array will have empty elements.
Range("A1").Resize(colScreener.Count, rngArea.Columns.Count).Value = varArray

Set colScreener = Nothing
End Function
'----------

"MarcL via OfficeKB.com" <u19204@uwe wrote in message
In my sheet, I have a range of data like this...
Class Total
500 20.0
500 12.0
500 35.5
502 28.3
502 13.7
503 19.3
504 21.4
504 30.7
504 14.5
In VBA, I need to copy the classes to an array, but with no duplicate.
I mean 500, 502, 503 and 504. How can I do that? Thank you in advance.


--
Message posted via http://www.officekb.com
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Copy Data From Cells To Array

Well you can pick up any set of range values using a Variant variable.
The result is a Variant containing an array.

Dim varArray as Variant
dim dblValue as Double

varArray = Range("B10: F30").Value
dblValue = varArray(3, 4)

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"MarcL via OfficeKB.com" <u19204@uwe wrote in message news:5cf3366dd5bdf@uwe...
Thank you Jim. But I am astonished that there is no function in Excel that
could do that... like filter advanced combined with copytoarray function.

Jim Cone wrote:
Something like this...
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'----------
Sub GetStarted()
Call NoEvilTwins(Selection)
End Sub
'----------

Function NoEvilTwins(ByRef rngArea As Excel.Range)
'Jim Cone - San Francisco, USA - March 07, 2006
Dim colScreener As VBA.Collection
Dim varArray() As Variant
Dim rngCell As Excel.Range
Dim lngC As Long
Dim lngR As Long

Set colScreener = New VBA.Collection
ReDim varArray(1 To rngArea.Rows.Count, 1 To rngArea.Columns.Count)
lngR = 1

For Each rngCell In rngArea.Columns(1).Cells
On Error Resume Next
colScreener.Add rngCell.Value, CStr(rngCell.Value)
If Err.Number = 0 Then
On Error GoTo 0
'Load the array
For lngC = 1 To rngArea.Columns.Count
varArray(lngR, lngC) = rngCell(1, lngC).Value
Next
lngR = lngR + 1
Else
Err.Clear
On Error GoTo 0
End If
Next

'Pick a place to put it.
'If there were duplicates then the array will have empty elements.
Range("A1").Resize(colScreener.Count, rngArea.Columns.Count).Value = varArray

Set colScreener = Nothing
End Function
'----------

"MarcL via OfficeKB.com" <u19204@uwe wrote in message
In my sheet, I have a range of data like this...
Class Total
500 20.0
500 12.0
500 35.5
502 28.3
502 13.7
503 19.3
504 21.4
504 30.7
504 14.5
In VBA, I need to copy the classes to an array, but with no duplicate.
I mean 500, 502, 503 and 504. How can I do that? Thank you in advance.


--
Message posted via http://www.officekb.com
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
Need data result in last cell of array that contains blank cells smesurfer Excel Discussion (Misc queries) 2 February 8th 10 10:51 PM
Copy data into cells until changes trigger new copy mdeanda Excel Programming 2 April 25th 05 01:32 PM
Copy Array pointer rather than entire array R Avery Excel Programming 2 August 24th 04 08:28 PM
efficiently copy values from a Range of cells to an array (in VB.N JW Excel Programming 0 June 22nd 04 11:17 AM
efficiently copy values from a Range of cells to an array (in VB.N JW Excel Programming 0 June 22nd 04 11:15 AM


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