ExcelBanter

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

nickm687

ActiveCell and TextBox
 
I have on my worksheet a textbox that i want to display a message
depending on which cell is highlighted.

im using this code for the updatung of the text box
ActiveSheet.TextBox1.Object.Value = "message"

depending on which cell is selected a different message will be shown.

thanks in advance
nick


Tom Ogilvy

ActiveCell and TextBox
 
Right click on the worksheet tab and select view code. In the left dropdown
at the top of the module select Workbook. From the right dropdown at the
top of the module select SelectionChange. You will get a event procedure
declaration like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

This will fire each time you change the selection, so you can use it to
update your textbox

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

--
Regards,
Tom Ogilvy

"nickm687" wrote in message
ps.com...
I have on my worksheet a textbox that i want to display a message
depending on which cell is highlighted.

im using this code for the updatung of the text box
ActiveSheet.TextBox1.Object.Value = "message"

depending on which cell is selected a different message will be shown.

thanks in advance
nick




nickm687

ActiveCell and TextBox
 
Brilliant, works perfectly.

Thank you
Nick


Tom Ogilvy wrote:
Right click on the worksheet tab and select view code. In the left dropdown
at the top of the module select Workbook. From the right dropdown at the
top of the module select SelectionChange. You will get a event procedure
declaration like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

This will fire each time you change the selection, so you can use it to
update your textbox

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

--
Regards,
Tom Ogilvy

"nickm687" wrote in message
ps.com...
I have on my worksheet a textbox that i want to display a message
depending on which cell is highlighted.

im using this code for the updatung of the text box
ActiveSheet.TextBox1.Object.Value = "message"

depending on which cell is selected a different message will be shown.

thanks in advance
nick



nickm687

ActiveCell and TextBox
 
One more question, this method works fine but doesnt work on merged
cells. any ideas?


nickm687 wrote:
Brilliant, works perfectly.

Thank you
Nick


Tom Ogilvy wrote:
Right click on the worksheet tab and select view code. In the left dropdown
at the top of the module select Workbook. From the right dropdown at the
top of the module select SelectionChange. You will get a event procedure
declaration like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

This will fire each time you change the selection, so you can use it to
update your textbox

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

--
Regards,
Tom Ogilvy

"nickm687" wrote in message
ps.com...
I have on my worksheet a textbox that i want to display a message
depending on which cell is highlighted.

im using this code for the updatung of the text box
ActiveSheet.TextBox1.Object.Value = "message"

depending on which cell is selected a different message will be shown.

thanks in advance
nick




All times are GMT +1. The time now is 03:34 AM.

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