Solved

Duplicate export to Excel

Posted on 2011-03-10
5
332 Views
Last Modified: 2012-05-11
Hello all,

This topic is to follow the first post:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26872084.html

In my MSHFlexgrid1, all row in green are duplicates.

I need to be able to click on a button and it will export to excel only the duplicate ones in green with the grid column names.

His this possible?

How can i do this?

Thanks again for your help
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35094764
Sure it is possible....
Remember from the Previous...
You have the Duplicates in the Last Column of you FlexGrid - marked with a value of 1...
Just go through your Grid and export the ones where it is marked..
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35095078
just place a button on your form...and run this...
set the filename as you wish...
Private Sub cmdOUT_Click()
    Dim oXL As Object
    Dim oBK As Object
    Dim oSH As Object
    Set oXL = CreateObject("Excel.Application")
    Set oBK = oXL.Workbooks.Add
    Set oSH = oBK.Worksheets(1)
    With MSHFlexGrid1
       For r = 0 To .Rows - 1
          .Row = r
          If r = 0 Then
             ' OUTPUT YOUR HEADERS
             For j = 0 To .Cols - 2
                .Col = j
                oSH.Cells(1, j + 1).Value = .Text
             Next
             iROW = iROW + 1
          Else
             .Col = .Cols - 1
             If .Text = 1 Then
                For j = 0 To .Cols - 2
                   .Col = j
                   oSH.Cells(iROW, j + 1).Value = .Text
                Next
                iROW = iROW + 1
             End If
          End If
       Next r
    End With
    oBK.SaveAs ("C:\Documents and Settings\all users\Desktop\Output.xls")
    oXL.Quit

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 35097597
Hello Brook1966.

OK i have put this code but i have an execution error 1004, error on the application or object:
oSH.Cells(irow, j + 1).Value = .Text

Open in new window




Full code:
Dim oXL As Object
 Dim r As Long
 Dim j As Long
 Dim irow As Long
    Dim oBK As Object
    Dim oSH As Object
    Set oXL = CreateObject("Excel.Application")
    Set oBK = oXL.Workbooks.Add
    Set oSH = oBK.Worksheets(1)
    With MSHFlexGrid1
       For r = 1 To .Rows - 1
          .Row = r
          If r = 0 Then
             ' OUTPUT YOUR HEADERS
             For j = 0 To .Cols - 2
                .Col = j
                oSH.Cells(1, j + 1).Value = .Text
             Next
             irow = irow + 1
          Else
             .Col = .Cols - 1
             If .Text = 1 Then
                For j = 0 To .Cols - 2
                   .Col = j
                   oSH.Cells(irow, j + 1).Value = .Text
                Next
                irow = irow + 1
             End If
          End If
       Next r
    End With
    oBK.SaveAs ("C:\Documents and Settings\all users\Desktop\Output.xls")
    oXL.Quit

Open in new window

0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 35109728
In this code you have...
Change the code on line 11...
FROM
For r = 1 To .Rows - 1
TO
For r = 0 To .Rows - 1
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 35112901
Perfect

Thanks again for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month7 days, 9 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question