Solved

Copy sected cell plus row 0 header

Posted on 2013-05-30
2
271 Views
Last Modified: 2013-05-31
Hello all

I have this macro that copy selected cells in the grid.
    'Copy the selection and put it on the Clipboard
    Clipboard.Clear
    Clipboard.SetText MSHFlexGrid2.Clip

Open in new window


But i would like to also copy by default the row o with the header. followed by the selected row.

For example:
in the picture below,
picture 1
 if i select the row 1 with the value A, B, C, D, and click copy, it will copy the headers and the A,B,C,D under

HEADER1      HEADER2      HEADER3      HEADER4
A              B              C              D


That way, i will be able to paste that into Excel.
How can i do that?

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
2 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 39209800
Try this

  Dim nCol As Long
  Dim sColHeaders As String

  With MSHFlexGrid2
    For nCol = 0 To .Cols - 1
        sColHeaders = sColHeaders & .TextMatrix(0, nCol) & Chr(9)
    Next nCol
    sColHeaders = Left$(sColHeaders, Len(sColHeaders) - 1)  'remove last Chr(9)
    
    'Copy the selection and put it on the Clipboard
    Clipboard.Clear
    'Clipboard.SetText MSHFlexGrid2.Clip 
    Clipboard.SetText sColHeaders & vbCrLf & .Clip 'Send to Clipboard
  End With

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39210746
Many thanks, this is perfect
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

751 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