Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveCell changes contents of TextBox
I have on a worksheet a textbox, and i want its contents to change
depending on the highlighted cell. For example: when A1 is selected the textbox contents are "msg1" when A6 is selected the textbox reads "msg2" Thanks in advance. Nick |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveCell changes contents of TextBox
This should do what you want but the sub will run EVERY TIME you select
a new cell. Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) dim mymsg as string if ActiveCell.Address="A1" then mymsg="String 1" elseif activecell.address="A6" then mymsg="String 2" else exit sub end if msgbox mymsg End Sub wrote: I have on a worksheet a textbox, and i want its contents to change depending on the highlighted cell. For example: when A1 is selected the textbox contents are "msg1" when A6 is selected the textbox reads "msg2" Thanks in advance. Nick |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveCell changes contents of TextBox
Thank you very much. Works a treat!
Alan wrote: This should do what you want but the sub will run EVERY TIME you select a new cell. Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) dim mymsg as string if ActiveCell.Address="A1" then mymsg="String 1" elseif activecell.address="A6" then mymsg="String 2" else exit sub end if msgbox mymsg End Sub wrote: I have on a worksheet a textbox, and i want its contents to change depending on the highlighted cell. For example: when A1 is selected the textbox contents are "msg1" when A6 is selected the textbox reads "msg2" Thanks in advance. Nick |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveCell changes contents of TextBox
Sorry, read the exam question and check your answer!!
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) dim mymsg as string if ActiveCell.Address="$A$1" then mymsg="String 1" elseif activecell.address="$A$6" then mymsg="String 2" else exit sub end if ActiveSheet.Shapes("Text Box").Select Selection.Characters.Text = mymsg End Sub Alan wrote: This should do what you want but the sub will run EVERY TIME you select a new cell. Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) dim mymsg as string if ActiveCell.Address="A1" then mymsg="String 1" elseif activecell.address="A6" then mymsg="String 2" else exit sub end if msgbox mymsg End Sub wrote: I have on a worksheet a textbox, and i want its contents to change depending on the highlighted cell. For example: when A1 is selected the textbox contents are "msg1" when A6 is selected the textbox reads "msg2" Thanks in advance. Nick |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveCell changes contents of TextBox
This would be a good place to use Select Case:
Select Case ActiveCell.Address Case "$A$1" mymsg="String 1" Case "$A$6" mymsg="String 2" case else exit sub end select Besides saving time, not having to write the same thing (activecell.address) to be tested multiple times, it runs faster. The Case tests can include combinations of multiple values, ranges of values, and inequalities (eg., Case 3, 6, 10 to 20 ; Case Is 8) "Alan" wrote: Sorry, read the exam question and check your answer!! Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) dim mymsg as string if ActiveCell.Address="$A$1" then mymsg="String 1" elseif activecell.address="$A$6" then mymsg="String 2" else exit sub end if ActiveSheet.Shapes("Text Box").Select Selection.Characters.Text = mymsg End Sub Alan wrote: This should do what you want but the sub will run EVERY TIME you select a new cell. Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) dim mymsg as string if ActiveCell.Address="A1" then mymsg="String 1" elseif activecell.address="A6" then mymsg="String 2" else exit sub end if msgbox mymsg End Sub wrote: I have on a worksheet a textbox, and i want its contents to change depending on the highlighted cell. For example: when A1 is selected the textbox contents are "msg1" when A6 is selected the textbox reads "msg2" Thanks in advance. Nick |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Echo Contents of ActiveCell into a Text box. | Excel Discussion (Misc queries) | |||
How To Print the contents of a TextBox | Excel Programming | |||
Contents of a TextBox to HTML | Excel Programming | |||
Copy named range contents to activecell position | Excel Programming | |||
clear textbox contents | Excel Programming |