Run-Time error '13' Type Mismatch - only when using specific code

cmerrick

Board Regular
Joined
Jun 8, 2017
Messages
78
Office Version
  1. 365
Platform
  1. Windows
So I have a UserForm that IÂ’m working on and have beentrying to hide/show a certain Label and Textbox based on the value of a ComboBox.






The code I am usingto do this is –


Code:
'hide HolidayRentTB & HolidayRentLa

[FONT=Calibri]If (PropertyTypeCB.Value) = "Single Unit" Or "Ex-Pat" Or "Holiday Let / AST" Then[/FONT]

[FONT=Calibri]    HolidayRentLa.Visible = False
[/FONT]
[FONT=Calibri]    HolidayRentTB.Visible = False[/FONT]
[FONT=Calibri]Else[/FONT]

[FONT=Calibri]    HolidayRentLa.Visible = True[/FONT]

[FONT=Calibri]    HolidayRentTB.Visible = True[/FONT]

[FONT=Calibri]End If[/FONT]


Note;


TB = TextBox

La = Label



CB = ComboBox


I have this inside of a larger set of code (below) which IÂ’musing to determine the ComboBox Values
For some reasonthough, the code above seems to causes the error in the title. It’s causing amodule I have, to ‘show’ the UserForm, to error)

As soonas I take the above code out again everything works.

Code:
[FONT=Calibri]Private Sub Userform_Initialize()[/FONT]





[FONT=Calibri]'hide HolidayRentTB & HolidayRentLa[/FONT]


[FONT=Calibri]If (PropertyTypeCB.Value) = "Single Unit" Or"Ex-Pat" Or "Holiday Let / AST" Then[/FONT]


[FONT=Calibri]   HolidayRentLa.Visible = False[/FONT]


[FONT=Calibri]   HolidayRentTB.Visible = False[/FONT]


[FONT=Calibri]Else[/FONT]


[FONT=Calibri]   HolidayRentLa.Visible = True[/FONT]


[FONT=Calibri]   HolidayRentTB.Visible = True[/FONT]


[FONT=Calibri]End If[/FONT]





[FONT=Calibri]'add items to the Property Type list[/FONT]


[FONT=Calibri]With PropertyTypeCB[/FONT]


[FONT=Calibri]    .AddItem"Single Unit"[/FONT]


[FONT=Calibri]    .AddItem"Ex-Pat"[/FONT]


[FONT=Calibri]    .AddItem"Holiday Let / HRI"[/FONT]


[FONT=Calibri]    .AddItem"Holiday Let / AST"[/FONT]


[FONT=Calibri]End With[/FONT]





[FONT=Calibri]'add items to the Product Type list[/FONT]


[FONT=Calibri]With ProductTypeCB[/FONT]


[FONT=Calibri]    .AddItem"Fixed"[/FONT]


[FONT=Calibri]    .AddItem"Variable"[/FONT]


[FONT=Calibri]End With[/FONT]





[FONT=Calibri]'add items to the Product Term (Months) list[/FONT]


[FONT=Calibri]With ProductTermMonthsCB[/FONT]


[FONT=Calibri]    .AddItem"0"[/FONT]


[FONT=Calibri]    .AddItem"12"[/FONT]


[FONT=Calibri]    .AddItem"24"[/FONT]


[FONT=Calibri]    .AddItem"36"[/FONT]


[FONT=Calibri]    .AddItem"48"[/FONT]


[FONT=Calibri]    .AddItem"60"[/FONT]


[FONT=Calibri]End With[/FONT]





[FONT=Calibri]'add items to the Tax Band Applicable list[/FONT]


[FONT=Calibri]With TaxBandApplicableCB[/FONT]


[FONT=Calibri]    .AddItem"Basic"[/FONT]


[FONT=Calibri]    .AddItem"Higher / Additional"[/FONT]


[FONT=Calibri]    .AddItem"Limited Company"[/FONT]


[FONT=Calibri]End With[/FONT]





[FONT=Calibri]'add items to the Product Fee Type list[/FONT]


[FONT=Calibri]With ProductFeeTypeCB[/FONT]


[FONT=Calibri]    .AddItem "Fee%"[/FONT]


[FONT=Calibri]    .AddItem "Fee£"[/FONT]


[FONT=Calibri]    .AddItem"Nil"[/FONT]


[FONT=Calibri]End With[/FONT]






[FONT=Calibri]End Sub[/FONT]






PS - Sorry for the strange layout of the text – my PCdoesn’t seem to like this Forum’s message box at all !




 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How about
Code:
Select Case PropertyTypeCB.Value
    Case "Single Unit", "Ex-Pat", "Holiday Let / AST"
        HolidayRentLa.Visible = False
        HolidayRentTB.Visible = False
    Case Else
        HolidayRentLa.Visible = True
        HolidayRentTB.Visible = True
End Select
 
Upvote 0
Thank you... can I use this within the larger private sub?


Edit -I tired it and it works – the user form doesn’t crash - but it’sdoesn’t function as expected (but I guess that’s a different issue)

 
Last edited:
Upvote 0
Yes, just replace this
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000][FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][FONT=Times New Roman][FONT=Calibri]If (PropertyTypeCB.Value) = "Single Unit" Or"Ex-Pat" Or "Holiday Let / AST" Then[/FONT]


[FONT=Calibri]   HolidayRentLa.Visible = False[/FONT]


[FONT=Calibri]   HolidayRentTB.Visible = False[/FONT]


[FONT=Calibri]Else[/FONT]


[FONT=Calibri]   HolidayRentLa.Visible = True[/FONT]


[FONT=Calibri]   HolidayRentTB.Visible = True[/FONT]


[FONT=Calibri]End If[/FONT][/FONT][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
with the code from Post#2
 
Upvote 0
Yes, just replace this
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000][FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][FONT=Times New Roman][FONT=Calibri]If (PropertyTypeCB.Value) = "Single Unit" Or"Ex-Pat" Or "Holiday Let / AST" Then[/FONT]


[FONT=Calibri]   HolidayRentLa.Visible = False[/FONT]


[FONT=Calibri]   HolidayRentTB.Visible = False[/FONT]


[FONT=Calibri]Else[/FONT]


[FONT=Calibri]   HolidayRentLa.Visible = True[/FONT]


[FONT=Calibri]   HolidayRentTB.Visible = True[/FONT]


[FONT=Calibri]End If[/FONT][/FONT][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
with the code from Post#2


Thank you for the above. Not sure if you saw my edit...?

Your code has worked in so much as it's stopped the UserForm from crashing but it hasn't actually hidden the intended Label and TextBox. Do you know why this might be?
 
Upvote 0
You've got that code in the intialize event, so the combo probably doesn't have a value.
Try moving it into the click event for the combo
Code:
Private Sub PropertyTypeCB_Click()
    Select Case PropertyTypeCB.Value
        Case "Single Unit", "Ex-Pat", "Holiday Let / AST"
            HolidayRentLa.Visible = False
            HolidayRentTB.Visible = False
        Case Else
            HolidayRentLa.Visible = True
            HolidayRentTB.Visible = True
    End Select
End Sub
 
Upvote 0
You've got that code in the intialize event, so the combo probably doesn't have a value.
Try moving it into the click event for the combo
Code:
Private Sub PropertyTypeCB_Click()
    Select Case PropertyTypeCB.Value
        Case "Single Unit", "Ex-Pat", "Holiday Let / AST"
            HolidayRentLa.Visible = False
            HolidayRentTB.Visible = False
        Case Else
            HolidayRentLa.Visible = True
            HolidayRentTB.Visible = True
    End Select
End Sub

I could kiss you my dude! x

Cheers mate
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,288
Members
448,885
Latest member
LokiSonic

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