Solved

Duplicate export to Excel

Posted on 2011-03-10
5
326 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now