Results 1 to 4 of 4

Thread: Anyone Help? Asked last week but got no answer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    22

    Unhappy

    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
    Using VBA

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    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
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    22
    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!!
    Using VBA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width