-
I've sorted and removed duplicates from a range of names, then created a new collection to hold the data. Instead of putting the contents of the collection into a list box, I want to write it to a worksheet range. As far as I've gotten is:
Code:
For Each Item In NoDupes
NEED SOMETHING HERE----
ActiveCell.Offset(1, 0).Select
Next Item
Anyone know the code to take each item from the collection, paste it to a worksheet, then take the next item and paste it in the cell directly below the first?
DESPERATE FOR HELP HERE>>>>PLEASE RESPOND IF YOU HAVE A THOUGHT ON THIS
-
I had a similar problem in a prog. I wrote a year ago. What I ended up doing, (although there is probobly an easier way) is loading all the (numbers, although names will work as well) into a variable array, then used the <> existing variable, then had it write it into a report. I don't know if this is what you are looking for, but I thought it may help.
Lee
-
Here is a little exmple:
Code:
Option Explicit
Dim m_colValues As New Collection
Private Sub Form_Load()
Dim i As Integer
'For this example I'm populating a dummy collection
For i = 1 To 10
m_colValues.Add "Item" & i, "Item" & i
Next
End Sub
Private Sub Command1_Click()
Dim objExcel As New Excel.Application
Dim objWorkgbook As Excel.Workbook
Dim objWorksheet As Excel.Worksheet
Dim objColItem As Variant
Dim i As Integer
objExcel.Visible = True
Set objWorkgbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkgbook.Worksheets.Add
'start from first row
i = 1
For Each objColItem In m_colValues
'Noticc
objWorksheet.Cells(i, 1).Value = objColItem
i = i + 1
Next
'These 2 lines of code needed when you're done using Excel
objWorkgbook.Close SaveChanges:=False
objExcel.Quit
End Sub
-
Thanks for responding...I figured it out already, though. I was trying to get too complicated when the answer was pretty simple actually. Once I had "filled" the collection, it was really a simple matter to write it to a worksheet range:
Code:
Range("Fund_Extract").Select
For Each Item In NoDupes
ActiveCell.Value = Item
ActiveCell.Offset(1, 0).Select
Next Item
Thanks for your input!!