Formatig cells

  • Thread starter Thread starter Khalil Handal
  • Start date Start date
K

Khalil Handal

Hi,
I created 50 similar TextBoxes containing numbers 1 to 50 with certain
color.
I wan to assign macrs to each TexBox so that:
1- copy the number inside the textbox to another cell (say D100)
2- set that cell (D100) active.
3- change the background color of the textbox to another color (say
yellow). This is to know which TextBox was selected & which was not
selected.

Any ideas.

Khalil
 
Hi,Khalil

Pls try follow VBA script in your xls file

'***********************************************
'the Vba script

Sub Chg_Color() 'change textbox's backcolor
i = 0
Do
i = i + 1
Loop Until i = 50 Or Controls("textbox" & CStr(i)).BackColor = RGB(255,
255, 0)
Controls("textbox" & CStr(i)).BackColor = -2147483643
End Sub

Private Sub TextBox1_Change()
Chg_Color
TextBox1.BackColor = RGB(255, 255, 0)
sheet1.cells(100,4) = textbox1 'suppose the range(D100) is in sheet1
End Sub

Private Sub TextBox2_Change()
Chg_Color
TextBox2.BackColor = RGB(255, 255, 0)
sheet1.cells(100,4) = textbox2
End Sub

'....
'every textbox's vba script is same ,but it need change the "number" in its
name

Private Sub TextBox50_Change()
Chg_Color
TextBox50.BackColor = RGB(255, 255, 0)
sheet1.cells(100,4) = textbox50
End Sub

'**************************************************************
 
Hi,
I tried but had the compilation error:

Comppile error:
Sub or Function not defined

in the line:
Loop until i=50 Or Controls.....

(the blue color on the word "Controls"


What I want is that when I click on the TextBox the change will take place.
(HopeI was clear from the begining)

Khalil
 
Back
Top