Solved

Duplicate export to Excel

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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