Dec 02 2022 06:37 AM - edited Dec 02 2022 06:40 AM
This must be the weirdest phenomenon I've ever faced.
Normally in Userform.ListBox.Font.Italic should works just like a range.
Private Sub UserForm_Initialize()
'this would works as expected
UserForm1.ListBox1.RowSource = "Sheet1!A1:A3"
UserForm1.ListBox1.Font.Italic = True
UserForm1.ListBox1.Font.Italic = False
End Sub
But see these two samples below.
Private Sub UserForm_Initialize()
'this will NOT works! Just because i assigned a range variable. HOW STRANGE
'Notice the list is stil italic even if i set .Italic = False
Dim test_rng As Range
Set test_rng = [b5]
UserForm2.ListBox1.RowSource = "Sheet1!A1:A3"
UserForm2.ListBox1.Font.Italic = True
UserForm2.ListBox1.Font.Italic = False
'MsgBox UserForm2.ListBox1.Font.Italic 'you can uncomment this line to check .Italic property, it's still TRUE
End Sub
Private Sub UserForm_Initialize()
'this will NOT works same! Because i assigned wildcard characters combined with textbox value to a variable. GOSH STRANGE.
'Notice the list is stil italic even if i set .Italic = False
Dim test_str As String
test_str = UserForm3.TextBox1.Value & "*"
UserForm3.ListBox1.RowSource = "Sheet1!A1:A3"
UserForm3.ListBox1.Font.Italic = True
UserForm3.ListBox1.Font.Italic = False
'MsgBox UserForm3.ListBox1.Font.Italic 'you can uncomment this line to check .Italic property, it's still TRUE
End Sub
The codes self-explained.
It just doesn't make any sense! how could possibly assign a range variable or wildcard+textbox value affects the italic property of listbox.
And the most weird thing is to fix this, just assign italic property in other module.
Call fixed
------------------
Sub fixed()
UserForm3.ListBox1.Font.Italic = False
End Sub
I have uploaded a sample file to clarify the issue.
Please leave any thoughts below ...
Dec 02 2022 06:57 AM
I cannot reproduce the problem. Even if I don't call fixed, the listbox font is not italic when I show UserForm2 and UserForm3.
I'm using Excel in Office 2021 on Windows 11. Which version of Office and which operating system do you use?
Dec 02 2022 08:32 AM - edited Dec 02 2022 08:36 AM
What!
i have 3 devices, Windows 10 with Office 2016, Windows 10 with Office 2021, Windows 7 with Office 2010. All of them behaves the same issue ....
here's a footage....
Dec 02 2022 09:22 AM
Oh, I don't doubt your experience at all. I've seen more than enough weird behavior...
Dec 02 2022 10:53 AM
SolutionDec 02 2022 12:55 PM
@PowerDekor that is odd behavior indeed. Another option that seems to work is to perform the italic operation BEFORE the problem causing actions:
Private Sub UserForm_Initialize()
'this will NOT works! Just because i assigned a range variable. HOW STRANGE
'Notice the list is stil italic even if i set .Italic = False
Dim test_rng As Range
UserForm2.ListBox1.RowSource = "Sheet1!A1:A3"
UserForm2.ListBox1.Font.Italic = True
UserForm2.ListBox1.Font.Italic = False
Set test_rng = [b5]
'MsgBox UserForm2.ListBox1.Font.Italic 'you can uncomment this line to check .Italic property, it's still TRUE
Call fixed 'And this would just fixed? by assign the property in other module? >_<
End Sub
notice I moved those 3 lines ABOVE the Set statement and it seems to work fine here and in the other case too
Dec 02 2022 10:53 AM
Solution