Solved

Copy sected cell plus row 0 header

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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 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…
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…

773 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