Floating VBA text box query

JohnsonFelix

New Member
Joined
Jul 22, 2011
Messages
15
Hi Team,

I have long text in one of the cell, Instead of displaying by doing wraptext in the cell, I thought to have a VBA text box, As soon as cell in clicked VBA text box will display the content in the text box
Function is working fine, however when I select a entire row, then I am getting VBA error.

run-time error 1004
Application-defined or object-defined error

VBA Code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgAddress As String
xRgAddress = "F11:f60"
If xRgAddress = "" Then
With TextBox1
.Top = Target.Top
.Left = Target.Offset(, 1).Left
.Text = Target.Text
.Visible = True
End With
Else
If Intersect(Target, Range(xRgAddress)) Is Nothing Then
TextBox1.Visible = False
Else
With TextBox1
.Top = Target.Top
.Left = Target.Offset(, 1).Left
.Text = Target.Text
.Visible = True
End With
End If
End If
End Sub

Could someone help me how this error can be avoided
Image.png
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You can add a line of code that exits the sub if more than one cell is selected...

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    'if more than one cell is selected, exit the sub
    If Target.CountLarge > 1 Then Exit Sub
    
    'etc
    '
    '
    
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,167
Members
448,870
Latest member
max_pedreira

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