ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ActiveCell and TextBox (https://www.excelbanter.com/excel-programming/372093-activecell-textbox.html)

nickm687

ActiveCell and TextBox
 
Hi,
I am using the code below to change the contents of a textbox depending
on which cell is highlighted. the code works fine but does not work on
a merged cell. any ideas?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Address(0,0)
Case "C1"
ActiveSheet.TextBox1.Value = "One"
Case "D3", "F1", "M12"
ActiveSheet.Textbox1.Value = "Two
Case Else
ActiveSheet.TextBox1.Value = ""
end Select
End Sub


Thanks
Nick


Tom Ogilvy

ActiveCell and TextBox
 
You would have to list all the cells in each merged cell range

Case "C1:D5"

for example.

Use copy of your workbook and put in a selectionchange event like this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
msgbox Target.Address(0,0)
End sub

and then you will see what is being returned for each type of cell you
select.

--
Regards,
Tom Ogilvy


"nickm687" wrote in message
ups.com...
Hi,
I am using the code below to change the contents of a textbox depending
on which cell is highlighted. the code works fine but does not work on
a merged cell. any ideas?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Address(0,0)
Case "C1"
ActiveSheet.TextBox1.Value = "One"
Case "D3", "F1", "M12"
ActiveSheet.Textbox1.Value = "Two
Case Else
ActiveSheet.TextBox1.Value = ""
end Select
End Sub


Thanks
Nick





All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com