Userform cmdbutton show when value in label exist

Fredric Andersson

New Member
Joined
Sep 30, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hello guys again,

i have a new problem that make me tear up my hair.
This is how my userform is (Last picture)

When there is a value in Nummer (like the one or two) i want to show the "Åtgärd för detta ärende"
Below is my code that i tought worked but dont work.

anyone have a soultion for this?

If riskanalys_dashboard.n1 <> "" Or riskanalys_dashboard.n2 <> "" Or riskanalys_dashboard.n3 <> "" Then

riskanalys_dashboard.cmd_åtgärd1.Visible = True
riskanalys_dashboard.cmd_åtgärd2.Visible = True
riskanalys_dashboard.cmd_åtgärd3.Visible = True
Else

riskanalys_dashboard.cmd_åtgärd1.Visible = False
riskanalys_dashboard.cmd_åtgärd2.Visible = False
riskanalys_dashboard.cmd_åtgärd3.Visible = False

End If

Br
Fredric


1729065782098.png
 

Attachments

  • 1729065740321.png
    1729065740321.png
    6.8 KB · Views: 5

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
'If this macro is located in a UserForm, try editing the code as such :

VBA Code:
If Me.riskanalys_dashboard.n1 <> "" Or Me.riskanalys_dashboard.n2 <> "" Or Me.riskanalys_dashboard.n3 <> "" Then

Me.riskanalys_dashboard.cmd_åtgärd1.Visible = True
Me.riskanalys_dashboard.cmd_åtgärd2.Visible = True
Me.riskanalys_dashboard.cmd_åtgärd3.Visible = True
Else

Me.riskanalys_dashboard.cmd_åtgärd1.Visible = False
Me.riskanalys_dashboard.cmd_åtgärd2.Visible = False
Me.riskanalys_dashboard.cmd_åtgärd3.Visible = False

End If

The "Me." tells Excel to refer to the UserForm code and not code located elsewhere in the project.
 
Upvote 0
'If this macro is located in a UserForm, try editing the code as such :

VBA Code:
If Me.riskanalys_dashboard.n1 <> "" Or Me.riskanalys_dashboard.n2 <> "" Or Me.riskanalys_dashboard.n3 <> "" Then

Me.riskanalys_dashboard.cmd_åtgärd1.Visible = True
Me.riskanalys_dashboard.cmd_åtgärd2.Visible = True
Me.riskanalys_dashboard.cmd_åtgärd3.Visible = True
Else

Me.riskanalys_dashboard.cmd_åtgärd1.Visible = False
Me.riskanalys_dashboard.cmd_åtgärd2.Visible = False
Me.riskanalys_dashboard.cmd_åtgärd3.Visible = False

End If

The "Me." tells Excel to refer to the UserForm code and not code located elsewhere in the project.
I see, i tried it but it didnt work.

i gott error messenge "compilation error cannot find method or data member"

Br
 
Upvote 0
If you can post your workbook for download that would be a big help. You'll have to use a cloud website like DropBox.com or similar.
 
Upvote 0
Hi
see if this update to your code does what you want

VBA Code:
Dim HasValue As Boolean

HasValue = Val(Me.N1) > 0 Or Val(Me.N2) > 0 Or Val(Me.N3) > 0

Me.cmd_åtgärd1.Visible = HasValue
Me.cmd_åtgärd2.Visible = HasValue
Me.cmd_åtgärd3.Visible = HasValue

Solution assumes that you are looking for any numeric value > 0 entered in any of the 3 textboxes for the commandbuttons to be visible

Dave
 
Upvote 0
@Fredric Andersson
I suspect you can call commandbutton name as you posted in OP !:cautious:
I think you renamed command button in caption option , not name option in windows properties.
why contains dot?!
Rich (BB code):
riskanalys_dashboard.cmd_åtgärd1.Visible
this is not properties !
of course the excel show "compilation error cannot find method or data member"
re-write name commandboutton where doesn't conflict with symbols uses in EXCEL system or WINDOWS.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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