error on floating textbox

R

rp

hi all! i have floating textbox on this excel file and what ever is the
content of the active cell appears on it. it works fine but when i try to
select 2 or more cells, an error appears. below is my code. please help

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
With ActiveWindow.VisibleRange
TextBox1.Top = .Top + 175
TextBox1.Left = .Left + .Width - TextBox1.Width - 120
TextBox1.Value = Target.Value
End With
End Sub
 
L

LanceB

When you select multiple cells you hav multiple target values that need to be
addressed:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim s As Variant, c As Range
With ActiveWindow.VisibleRange
TextBox1.Top = .Top + 175
TextBox1.Left = .Left + .Width - TextBox1.Width - 120
If Target.Cells.Count > 1 Then
For Each c In Target.Cells
s = s & c.Value & ","
Next c
TextBox1.Value = s
Else
TextBox1.Value = Target.Value
End If

End With
End Sub


Lance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top