Solved

Copy sected cell plus row 0 header

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

628 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