Textbox help

Al Chara

MrExcel MVP
Joined
Feb 21, 2002
Messages
1,701
Hi All,

I have a number of text boxes that were created dynamically at run time. When they were created I had the background color set to red. Is there a way to have the background color yellow when the text box is being typed in and then turn green after it has been typed in.

The textboxes are named mytextboxes(counter) where counter is a number from 1 to 100.

The problem that I run into is that I cannot declare an on click action because the text boxes are created at run time.

Any help would be greatly appreciated.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I went to the site and couldn't find the link to adding code at run time. I am not too familiar with class modules. Can you post some sample code of how I can change the background color of any textbox if the textbox has been clicked and then change it to another color once it is not active anymore? Thank you for any help you can give.
 
Upvote 0
It's described here by Chip:

Adding A Procedure To A Module

The procedure below will add a new procedure called "MyNewProcedure" to the module named "NewModule" in ThisWorkbook.

Sub AddProcedure()

Dim VBCodeMod As CodeModule
Dim LineNum As Long

Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("NewModule").CodeModule
With VBCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, _
"Sub MyNewProcedure()" & Chr(13) & _
" Msgbox ""Here is the new procedure"" " & Chr(13) & _
"End Sub"
End With

Application.Run "MyNewProcedure"

End Sub

Cheers, Nate
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top