Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Browse Forms Controls and change TextBox color based on cell color

Hi!

I would like to dynamically change the background color in an array of
TextBoxes in a Form, based on background colors in corresponding cells on the
sheet.
The textboxes are named so that they can be adressed but how do i typecast a
recieved Control from the Controls collection to a TextBox control (I get
type mismatch errors) and how do I set the BackColor-property ?

I would be greatful for advices on this matter!
// Sample pseudo-code below

Best regards,
StefanW



Private Sub SetBackgnd()
Dim tb As TextBox
Dim x, y As Integer

For y = 1 To 13
For x = 1 To 3
Set tb = MyForm.Controls("row" & y & "col" & x) <- I get error
here
'Change background color of TextBox named "row'y'col'x'"
'based on backgroundcolor in Range("A1").Offset(row,col)
Next res
Next mt
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Browse Forms Controls and change TextBox color based on cell color

If all your indexes are correct, it could be as simple as your dim statement:

Dim tb As msforms.TextBox

There are two Textboxes in excel--one from the Drawing toolbar and one from the
control toolbox toolbar (used in Userforms).

If you don't qualify which one you want, you'll get the drawing toolbar version.

===
There are other objects that are like this, too. You may want to start fully
qualifying those controls in your userform--just in case.


StefanW wrote:

Hi!

I would like to dynamically change the background color in an array of
TextBoxes in a Form, based on background colors in corresponding cells on the
sheet.
The textboxes are named so that they can be adressed but how do i typecast a
recieved Control from the Controls collection to a TextBox control (I get
type mismatch errors) and how do I set the BackColor-property ?

I would be greatful for advices on this matter!
// Sample pseudo-code below

Best regards,
StefanW

Private Sub SetBackgnd()
Dim tb As TextBox
Dim x, y As Integer

For y = 1 To 13
For x = 1 To 3
Set tb = MyForm.Controls("row" & y & "col" & x) <- I get error
here
'Change background color of TextBox named "row'y'col'x'"
'based on backgroundcolor in Range("A1").Offset(row,col)
Next res
Next mt
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Browse Forms Controls and change TextBox color based on cell c

Thanx alot Dave!
Your solution was like magic to my application!

Best regards,
StefanW


"Dave Peterson" wrote:

If all your indexes are correct, it could be as simple as your dim statement:

Dim tb As msforms.TextBox

There are two Textboxes in excel--one from the Drawing toolbar and one from the
control toolbox toolbar (used in Userforms).

If you don't qualify which one you want, you'll get the drawing toolbar version.

===
There are other objects that are like this, too. You may want to start fully
qualifying those controls in your userform--just in case.


StefanW wrote:

Hi!

I would like to dynamically change the background color in an array of
TextBoxes in a Form, based on background colors in corresponding cells on the
sheet.
The textboxes are named so that they can be adressed but how do i typecast a
recieved Control from the Controls collection to a TextBox control (I get
type mismatch errors) and how do I set the BackColor-property ?

I would be greatful for advices on this matter!
// Sample pseudo-code below

Best regards,
StefanW

Private Sub SetBackgnd()
Dim tb As TextBox
Dim x, y As Integer

For y = 1 To 13
For x = 1 To 3
Set tb = MyForm.Controls("row" & y & "col" & x) <- I get error
here
'Change background color of TextBox named "row'y'col'x'"
'based on backgroundcolor in Range("A1").Offset(row,col)
Next res
Next mt
End Sub


--

Dave Peterson

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
Change tab color based on current color of a cell MarkT Excel Discussion (Misc queries) 0 May 22nd 08 05:46 PM
Can you change the color of one cell based on the color of another andoscott Excel Discussion (Misc queries) 4 May 4th 07 04:02 PM
Excel: Syntax to change cell color based on color of another cell davew18 Excel Worksheet Functions 1 January 4th 07 01:24 PM
Change tab color based on a cell value Zenaida Excel Discussion (Misc queries) 14 April 27th 06 10:35 PM
Q: How to change tab color based on cell value John[_60_] Excel Programming 1 February 22nd 04 10:58 AM


All times are GMT +1. The time now is 01:22 PM.

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"