views:

681

answers:

3

Hi, I want to copy some data from an excel file to a textbox in a win app. The copy paste works ok if the cells are continuos, but if I select (with CTRL) the first and the third cell, when I paste it to the textbox, it will paste also the 2nd cell. What is the best way to get just the cells i'm interested in? Thank you

+1  A: 

The only way I have found is to copy the two interesting columns, re-paste them next to each other somewhere in Excel, (like a new spreadsheet) re-copy, and paste into the textbox.

Textboxes really aren't meant for data that is in a grid view. If you are creating the textbox, I recommend that you try some kind of grid view control instead.

If you must use a textbox, I also recommend pasting the data with some sort of delimiter, like commas, to separate the data in rows, otherwise it's going to be difficult to work with when it is pulled out of the box.

NickSentowski
A: 

There is no way around this, as this is just the way that Excel interacts with windows. You will need to either copy/paste each cell individually, or copy/paste then delete the superfluous value.

If this a repetitive task, you may consider scripting it. There are a plethora of scripting options available and those will depend on your skill level and the OS you're running.

If you're not inclined to write, say, a vbscript for this, you could consider a free program like shortkeys. This is a text replacement tool, and since your copy/paste can be done all with the keyboard, this could be a simpler alternative.

TimS
A: 

I could think of one way to solve this.. If your source excel file is consatant and not generated by some other tool/macro or webpage and if you can add macros in it, then you can give it a try..

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Dim oSelection As Range, oWorkbook As Workbook
Application.ScreenUpdating = False  
Set oSelection = Selection
Set oWorkbook = Application.Workbooks.Add
Application.Windows(oWorkbook.Name).Visible = False
oWorkbook.Sheets(1).Paste
oWorkbook.Sheets(1).Range("A1:" & oWorkbook.Sheets(1).Cells(500, 1).End(xlUp).Address).Copy
oWorkbook.Close False
Application.ScreenUpdating = True
End Sub

But after penning this down I am not sure if Window Deactivate will triggered if you tabout from Excel to another windows app.. I think it will happen only if you tab out to another Excel file window..

Adarsha