Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Collection - object required message

I would like to add things in my collection but doesn't work all the time.

If I write:
Dim C as New Collection
For j = 1 To 10
C.Add Cells(j,5), Cells(j,5)
Next j
C(2) = C(1) 'this works

If I want to add other things then cells(j,5), it doesn't work
Dim C as New Collection
Dim D as New Collection
Dim Temp as Object
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing ?
Temp2 = "A-C" 'Temp2 is not empty
C.Add Temp, Temp 'doesn't work because Temp is empty
D.Add Temp2, Temp2 'seems to work but D(2) = D(1) doesn't work (object
required)
Next j
--
Alex St-Pierre
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Collection - object required message

Dim Temp as Variant or String, not as Object

Dim C as New Collection
Dim D as New Collection
Dim Temp as Variant
Dim Temp2 as Variant
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing
Temp2 = "A-C"
C.Add Temp, cStr(Temp)
D.Add Temp2, cStr(Temp2)
Next j

--
Regards,
Tom Ogilvy


"Alex St-Pierre" wrote in message
...
I would like to add things in my collection but doesn't work all the time.

If I write:
Dim C as New Collection
For j = 1 To 10
C.Add Cells(j,5), Cells(j,5)
Next j
C(2) = C(1) 'this works

If I want to add other things then cells(j,5), it doesn't work
Dim C as New Collection
Dim D as New Collection
Dim Temp as Object
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing ?
Temp2 = "A-C" 'Temp2 is not empty
C.Add Temp, Temp 'doesn't work because Temp is empty
D.Add Temp2, Temp2 'seems to work but D(2) = D(1) doesn't work (object
required)
Next j
--
Alex St-Pierre



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Collection - object required message

Hi Toms,
It gives an error message when I try to replace C(1) by C(2).

Dim Temp as String
For j = 1 to 100
Temp = Cells(j, 3) & "-" & Cells(j, 4)
C.Add Temp, CStr(Temp)
Next j
a = C(1)
b = C(2)
On Error GoTo 0
For iCtr = 1 To C.Count - 1 'Tri vecteur
For jCtr = iCtr + 1 To C.Count
If C(iCtr) < C(jCtr) Then
Temp = C(iCtr)
C(iCtr) = C(jCtr) 'C(1) = C(2) gives error message object is
required?
' C(1) = "A-.*" and C(2) = "A-A"
C(jCtr) = Temp
End If
Next jCtr
Next iCtr
--
Alex St-Pierre


"Tom Ogilvy" wrote:

Dim Temp as Variant or String, not as Object

Dim C as New Collection
Dim D as New Collection
Dim Temp as Variant
Dim Temp2 as Variant
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing
Temp2 = "A-C"
C.Add Temp, cStr(Temp)
D.Add Temp2, cStr(Temp2)
Next j

--
Regards,
Tom Ogilvy


"Alex St-Pierre" wrote in message
...
I would like to add things in my collection but doesn't work all the time.

If I write:
Dim C as New Collection
For j = 1 To 10
C.Add Cells(j,5), Cells(j,5)
Next j
C(2) = C(1) 'this works

If I want to add other things then cells(j,5), it doesn't work
Dim C as New Collection
Dim D as New Collection
Dim Temp as Object
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing ?
Temp2 = "A-C" 'Temp2 is not empty
C.Add Temp, Temp 'doesn't work because Temp is empty
D.Add Temp2, Temp2 'seems to work but D(2) = D(1) doesn't work (object
required)
Next j
--
Alex St-Pierre




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Collection - object required message

Sub AA()
Dim C As New Collection
Dim Temp As String
On Error Resume Next
For j = 1 To 100
Temp = Cells(j, 3) & "-" & Cells(j, 4)
C.Add Temp, CStr(Temp)
Next j
a = C(1)
b = C(2)
On Error GoTo 0
For ictr = 1 To C.Count - 1 'Tri vecteur
For jctr = ictr + 1 To C.Count
If C(ictr) < C(jctr) Then
Temp = C(ictr)
Temp1 = C(jctr)
C.Add Temp, Befo=jctr
C.Add Temp1, Befo=ictr
C.Remove ictr + 1
C.Remove jctr + 1
End If
Next jctr
Next ictr


End Sub


--
Regards,
Tom Ogilvy

"Alex St-Pierre" wrote in message
...
Hi Toms,
It gives an error message when I try to replace C(1) by C(2).

Dim Temp as String
For j = 1 to 100
Temp = Cells(j, 3) & "-" & Cells(j, 4)
C.Add Temp, CStr(Temp)
Next j
a = C(1)
b = C(2)
On Error GoTo 0
For iCtr = 1 To C.Count - 1 'Tri vecteur
For jCtr = iCtr + 1 To C.Count
If C(iCtr) < C(jCtr) Then
Temp = C(iCtr)
C(iCtr) = C(jCtr) 'C(1) = C(2) gives error message object

is
required?
' C(1) = "A-.*" and C(2) = "A-A"
C(jCtr) = Temp
End If
Next jCtr
Next iCtr
--
Alex St-Pierre


"Tom Ogilvy" wrote:

Dim Temp as Variant or String, not as Object

Dim C as New Collection
Dim D as New Collection
Dim Temp as Variant
Dim Temp2 as Variant
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing
Temp2 = "A-C"
C.Add Temp, cStr(Temp)
D.Add Temp2, cStr(Temp2)
Next j

--
Regards,
Tom Ogilvy


"Alex St-Pierre" wrote in

message
...
I would like to add things in my collection but doesn't work all the

time.

If I write:
Dim C as New Collection
For j = 1 To 10
C.Add Cells(j,5), Cells(j,5)
Next j
C(2) = C(1) 'this works

If I want to add other things then cells(j,5), it doesn't work
Dim C as New Collection
Dim D as New Collection
Dim Temp as Object
For j = 1 To 10
Temp = "A-C" 'Temp = Nothing ?
Temp2 = "A-C" 'Temp2 is not empty
C.Add Temp, Temp 'doesn't work because Temp is empty
D.Add Temp2, Temp2 'seems to work but D(2) = D(1) doesn't work

(object
required)
Next j
--
Alex St-Pierre






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 Help with Set Object = Collection(index) Trip[_3_] Excel Programming 1 October 19th 05 03:41 PM
Getting "Object Required" Error Message - Need Help !!! [email protected] Excel Programming 3 November 22nd 04 02:53 PM
Collection Object Keys Todd Huttenstine Excel Programming 10 October 29th 04 01:14 PM
CombBox - Object of What Collection? George Excel Programming 7 February 10th 04 12:01 AM
object required error message goss[_10_] Excel Programming 6 January 23rd 04 10:22 PM


All times are GMT +1. The time now is 02:37 AM.

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"