Paste from Clipboard

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Hi
My following code, pastes from clipboard. I have set the Control Source for Textbox2 as Cover!$B$2 as I want the data pasted in to B2 down.

This is the problem
It pastes ALL of the data in B2, so if I have copied 10 rows it pastes all data in B2, where as I would like it to paste the first row in B2 and the B3 and so on

VBA Code:
Private Sub CommandButton6_Click()
'Pastes from ClipBoard
Dim objdataobject As MSForms.DataObject
Set objdataobject = New MSForms.DataObject
objdataobject.GetFromClipboard
If Me.TextBox1.Value = "" Then
Me.TextBox1.Value = objdataobject.GetText
Exit Sub
End If

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Its ok, I think I have done it with this

VBA Code:
Private Sub CommandButton6_Click()

 Dim Str As String, a
 Dim cnt As Integer
 Dim w()
 
 Str = TextBox1.Value
  a = Chr(10)
   cnt = UBound(Split(Str, a))
 ReDim w(1 To cnt + 1, 1 To 1)
 
 For i = 0 To cnt
  w(i + 1, 1) = Split(Str, Chr(10))(i)
 Next i

 Sheet6.Range("A2").Resize(i, 1) = w

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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