Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Echo Contents of ActiveCell into a Text box. ChrisR Excel Discussion (Misc queries) 2 September 17th 09 04:00 PM
How To Print the contents of a TextBox DMS Excel Programming 1 September 30th 05 11:13 PM
Contents of a TextBox to HTML [email protected] Excel Programming 0 January 27th 05 06:40 PM
Copy named range contents to activecell position Neal Excel Programming 2 October 28th 04 02:20 PM
clear textbox contents dirt Excel Programming 1 January 27th 04 04:25 AM


All times are GMT +1. The time now is 11:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"