update label caption based on option button

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. Windows
I'd like a label caption to dynamically update based on a value ('factor') selected with 5 option buttons (per hour/day/week/month/year)
the label in the last line shows the MCV value, but does not update with ' factor' when I click another option button.

VBA Code:
Private Sub Mat_TotCommercialValue()
Dim factor As Integer
Dim MCV As Long

Select Case True
    Case OptHour: factor = Range("E_OperatingDays.Value") * Range("E_OperatingHours.Value") / 12
    Case OptDay: factor = Range("E_OperatingDays.Value") / 12
    Case OptWeek: factor = 52 / 12
    Case OptMonth: factor = 1
    Case OptYear: factor = 12
End Select

    MCV = Val(txtCommercialValue.Value)
    lblCommercialValue.Caption = Format(MCV / factor, "#,##0")
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Have you implemented a Change Event procedure for each option button that's invoking this code? If not, there's no dynamically update.
Furthermore, I would like to note that all divisions are rounded off arithmetic since you declared the variable named factor as an Integer. If this is not your intention then I would suggest changing its memory type to Double.
 
Upvote 0
You are right GWteB... I forgot the change events and now it works perfect. After I placed this message, I found out myself that indeed the Integers should be changed into Doubles. All good now! Thanks again,
Arie
 
Upvote 0
Glad it's sorted and thanks for letting me know.
 
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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