Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-12-28
10
Medium Priority
?
288 Views
Last Modified: 2012-12-28
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
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
  • 5
  • 3
  • 2
10 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 38726895
Hi,

Shouldn't you refer to TextBox2 on line 12

Regards
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726904
Hi Rgonzo1971

Well the textbox is in a VB6 form and not in Excel.
The texbox name is Text2.
Thanks
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726914
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

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38726918
the runtime error 91 means "object not set" ...
on which line? on which variable?

while stepping through the code, it should become obvious
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 38726920
> this but it past everything on 1 row
is the textbox defined to be "multiline"?
0
 
LVL 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1000 total points
ID: 38726923
Hi,

Are you sure you have multiline property true

Regards
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726942
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

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38726956
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

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38726972
good :)
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38727041
Thanks again for your help

all good now
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

730 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