Solved

Duplicate export to Excel

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 115
Problem to skip loop 6 56
SLMGR Switches Are Not Working On KMS Host 3 90
VBA - Excel, Hide/unhide range of rows on sheet with listbox selection 9 46
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

785 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