VB6- Copy a row from excel and paste it in Text2 VB6 issue

Wilder1626
Wilder1626 used Ask the Experts™
on
Hello all

I'm trying to copy a row from an excel file and paste it in my VB6 project in a Text2 as multiline but i have a hard time with it.

I'm trying this way:
If Text2 <> "" Then
MsgBox "Data already in Textbox"
Else
Dim varData
    If Selection.Rows.Count > 1 Then
        varData = Join(Application.Transpose(Selection.Value), vbCr)
    ElseIf Selection.Columns.Count > 1 Then
        varData = Join(Application.Transpose(Application.Transpose(Selection.Value)), vbCr)
    Else
        varData = Selection.Value
    End If
    With Me.Text2

        .Text = varData
    End With
 End If

Open in new window


But i have this run time error 91.

How can i fix this please?

Thanks again for your help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Hi,

Shouldn't you refer to TextBox2 on line 12

Regards
Hi Rgonzo1971

Well the textbox is in a VB6 form and not in Excel.
The texbox name is Text2.
Thanks
I have also tried like this but it past everything on 1 row

Private Sub test1_Click()
    Dim sText As String

    sText = Clipboard.GetText
    Text2.Text = Trim(Replace(sText, vbTab, vbCrLf))

End Sub

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
the runtime error 91 means "object not set" ...
on which line? on which variable?

while stepping through the code, it should become obvious
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
> this but it past everything on 1 row
is the textbox defined to be "multiline"?
Top Expert 2016
Commented:
Hi,

Are you sure you have multiline property true

Regards
Hi angelIII

Yes, the Text2 is set to be Multiline but still pasting on the same row using that code bellow:
Private Sub test1_Click()
    Dim sText As String

    sText = Clipboard.GetText
    Text2.Text = Trim(Replace(sText, vbTab, vbCrLf))

End Sub

Open in new window

I think i had a issue with the textbox itself.

I deleted that textbox and created a new one and called it Text3 with a Multiline yes and now it work with :

Private Sub test1_Click()
    Dim sText As String

    sText = Clipboard.GetText
    Text3.Text = Trim(Replace(sText, vbTab, vbCrLf))

End Sub

Open in new window

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
good :)
Thanks again for your help

all good now

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial