Copy .csv contents from clipboard to a spreadsheet

sparky2205

Active Member
Joined
Feb 6, 2013
Messages
480
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Folks,
I have a .csv file which contains data spread across a number of rows and columns.
I want the user to be able to copy this data to the clipboard and then run a macro that will take this data from the clipboard and paste it into a spreadsheet called "Data" beginning at cell A2.

I currently have:
VBA Code:
Sub GetData()

Dim MyData As DataObject
Dim sText As String

Set Data = ThisWorkbook.Worksheets(1)
Set MyData = New DataObject
MyData.GetFromClipboard
sText = MyData.GetText

'ThisWorkbook.Worksheets(1).Range("A2").Value = sText
Data.Range("A2").Value = sText

End Sub

But this puts all the data into cell A2 on Data.
What I need is a way to have Excel understand that the data being pasted is a range that should be pasted starting at A2.
I want the Data worksheet to look the same as the .csv file, from a data perspective. There are some header rows on the Data spreadsheet as well.
 
@Anthony47, it's probably something daft I'm doing.

@Anthony47, @GWteB;
Thanks a million to both of you for your time on this.
With your help I now have a very nice, user friendly method to achieve what I need.
Another successful visit to MREXCEL.COM
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top