(RESOLVED)Collection in Excel
Sorry to be asking about Excel in here but I've searched and noticed there are people in here who seem to know alot about it. I am working in VBE and though it is very much just like VB6 I'm not used to working with spreadsheets. I am looping through the rows and columns looking for cells with certain values - when I find them I need to add the corresponding cell value to a collection to be printed out to a text file. I am having no problem with the looping but can't figure out how or where to declare my collection. I did it at the top of my module but I'm not able to access it. When I type in MyCollection. there is no drop down list of properties so I'm assuming I haven't created my collection properly. Any help would be great as I'm completely new to this. Here's my code so far :confused:
(BTW - I realize this code is probably way off but I'v e never done this before so forgive me.)
Code:
Option Explicit
Public colFields As Collection
Sub FieldIDs()
'
' FieldIDs Macro
' Macro recorded 12/14/2004 by Lisa
'
Dim r, c
Dim numRows As Integer
Dim numColumns As Integer
Dim MySheet As Worksheet
For c = 5 To 18
For r = 8 To 150
MySheet = ActiveWorkbook.ActiveSheet
MySheet.Cells(c, r).Activate
MySheet.Cells(c, r).Select
If Range(c + 1, r).Value = "Y" Then
AddField Range(5, r)
End If
Next
Next
End Sub
Private Sub AddField(ByVal FieldId As String)
'add appropriate FieldId to collection
colFields.Add FieldId
End Sub
Private Sub PrintFields()
Dim intInHandle As Integer
Dim Field As colFields
intOutHandle = FreeFile()
Open "C:\Documents and Settings\Tryit.csv" For Output As #intOutHandle
For Each Field In colFields
'print #intOutHandle ??
Close #intOutHandle
End Sub