NinetalesOCE
New Member
- Joined
- Dec 15, 2021
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Good afternoon all
I need some help with my Userform and textboxes.
Overview Goal:
1. User ticks checkbox1
2. Checkbox1 then highlights Textbox1, textbox3 and textbox4.
3. User ticks checkbox 3
2. Checkbox3 then Highlights textbox1, textbox 4 and textbox 6.
4. User unticks checkbox1
5. Textbox3 returns to white background, and textbox 1, 4 and 6 stay yellow.
What I have so far is sort of a brainstorm:
But as you can see, the code is a mess and i can't work out how to de-colour the non-relevant textboxes without affecting the ones that were already coloured.
Any help would be appreciated!
I need some help with my Userform and textboxes.
Overview Goal:
- User opens the userform.
- User selects a checkbox.
- The checkbox then highlights the textboxes inside the userform that they are required to fill out.
- Highlighted = colour of the background changes to yellow.
- If the user clicks a second checkbox, it keeps the relevant textboxes highlighted for both checkboxes.
- If the user unticks a checkbox, it keeps all the required checkboxes highlighted.
1. User ticks checkbox1
2. Checkbox1 then highlights Textbox1, textbox3 and textbox4.
3. User ticks checkbox 3
2. Checkbox3 then Highlights textbox1, textbox 4 and textbox 6.
4. User unticks checkbox1
5. Textbox3 returns to white background, and textbox 1, 4 and 6 stay yellow.
What I have so far is sort of a brainstorm:
VBA Code:
Public yellow As String, White As String
'Creating the colours
Private Sub UserForm_Initialize()
yellow = RGB(255, 255, 0)
White = RGB(255, 255, 255)
End sub
'Calling the module
Public TestVariable(20) As MSForms.TextBox
Call TextBoxVariable
End Sub
'I was intending on doing some form of For i = (All of the values in TestValue) and then nexting through all of them to change the colours
Sub TextBoxVariable()
Set TestVariable(1) = GenerationForm.TextBox1
Set TestVariable(2) = GenerationForm.TextBox2
Set TestVariable(3) = GenerationForm.TextBox3
Set TestVariable(4) = GenerationForm.TextBox4
Set TestVariable(5) = GenerationForm.TextBox5
End Sub
'Goal was to assign a number, which is linked to the same numbered textbox as the below variable.
Private Sub CheckBox1_Click()
TestValue = Array("1", "2", "4")
For i = '(Values in TestValue)
'--Uncolour everything--
'--Recolour everything currently ticked--
TestVariable(i).BackColor = Yellow
End Sub
But as you can see, the code is a mess and i can't work out how to de-colour the non-relevant textboxes without affecting the ones that were already coloured.
Any help would be appreciated!