Solved

Duplicate export to Excel

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 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