Combobox excel/Vba

decoi

New Member
Joined
May 18, 2011
Messages
1
hello everyone..

ive a small yet annoying problem that ive been trying to figure out for the last 5 or so days..

what i have is a userform that allows you to change the font( fontname,colour,bold,underline etc)

i have everythign working apart from the fontnames. these ar populated in the combobox( lists names of text, only a select 5 "arial", Times New", "garamaond", "Comic Sans")

all these functions change the properties of the text in a Cell, not a textbox. the problem is getting the font to change when it is selected from the combobox. but only applied when the "Ok" button is clicked

heres the code so far:

cmdok is the ok button( after clicked the target cell is updated)
cbofont is the combobox
txtimput= is the text imput box the code, uses the text in the textbox then displays it in a cell


Option Explicit
Private Sub cmdok_Click()
Dim mytext As String
mytext = txtinput.Text
Range(rfecell.Text).Activate
ActiveCell.Formula = mytext
If optred.Value = True Then
ActiveCell.Font.Color = vbRed

ElseIf optgreen.Value = True Then
ActiveCell.Font.Color = vbGreen
ElseIf optblue.Value = True Then
ActiveCell.Font.Color = vbBlue
End If
If chkund = True Then

ActiveCell.Font.Underline = xlUnderlineStyleSingle
Else
ActiveCell.Font.Underline = False
End If
If chkbold = True Then
ActiveCell.Font.Bold = True
Else
ActiveCell.Font.Bold = False
End If
End Sub

Sub Userform_Initialize()
optred.Value = True
chkbold.Value = True
With cbofont
.AddItem "Times New Roman"
.AddItem "Comic Sans MS"
.AddItem "Garamond"
.AddItem "Arial"
.ListIndex = 0

End With
End Sub
Private Sub cbofont_Click()
Select Case cbofont
Case Is = "Times New Roman"
ActiveCell.Font.Name = "Times New Roman"
End Select
End Sub

Private Sub cmdquit_Click()
Unload Me
End Sub

thank you
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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