Solved

Copy sected cell plus row 0 header

Posted on 2013-05-30
2
266 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

705 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

13 Experts available now in Live!

Get 1:1 Help Now