type mismatch error passing multiple items with byref

CsJHUN

Active Member
Joined
Jan 13, 2015
Messages
360
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. Mobile
Hello guys,
in advance im just learing the passing values between subs (no clue about classes too :) ), also a lazy a.. for declare items.
I have a userform with (for example) a simple 2x2 + headline (3x3) crosstable. I have option buttons in the data field. I want to color the x(A or B) and y(1 or 2) headline of the clicked radio button.

[TABLE="class: grid, width: 120, align: center"]
<tbody>[TR]
[TD="align: center"]tbl
[/TD]
[TD="align: center"]Headline A
[/TD]
[TD="align: center"]Headline B
[/TD]
[/TR]
[TR]
[TD="align: center"]Headline 1
[/TD]
[TD="align: center"]o A1
[/TD]
[TD="align: center"]o B1
[/TD]
[/TR]
[TR]
[TD="align: center"]Headline 2
[/TD]
[TD="align: center"]o A2
[/TD]
[TD="align: center"]o B2
[/TD]
[/TR]
</tbody>[/TABLE]

So if clicked on A1 then headline A and headline 1 would be red.
Of course the original "table" is bigger than the example (currently 9x7)
The headlines are labels, the "data" is option button (radio button)


I have this:
Code:
Private Sub opbtnclick(ByRef opbtn As OptionButton, ByRef lblx As Label, ByRef lbly As Label)
    lblx.BackColor = vbRed
    lbly.BackColor = vbRed
End Sub

Private Sub opbtn_1_1_Click()
opbtnclick Me.opbtn_1_1, Me.lbl_1_0, Me.lbl_0_1
End Sub

Private Sub opbtn_1_2_Click()
opbtnclick Me.opbtn_1_2, Me.lbl_0_2, Me.lbl_1_0
End Sub

And this gives me type mismatch error.

Help me understand this, thanks
John
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I clicked reply when OP post was the only post. It took some time to find a workaround since I was playing with the code for a while to try to figure it out.
 
Upvote 0
BTW, when a button is clicked, should all previous labels be cleared of the red colour?

yes, i made a for loop for it, and inserted before coloring it to red :)
Code:
Private Sub label_reset()
Dim ctrl As Control
For Each ctrl In Me.Controls
    If TypeName(ctrl) = "Label" Then
        ctrl.BackColor = vbMenuBar
    End If
Next ctrl
End Sub

ps.: thanks pbornemeier :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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