Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy sected cell plus row 0 header

Posted on 2013-05-30
2
Medium Priority
?
273 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

715 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