Home Schroedinger's label caption update
Reply: 1

Schroedinger's label caption update

jvk
1#
jvk Published in 2017-12-07 16:57:11Z

I have some code in VBA that goes like this:

Sub UserForm2_Activate()
....
If [statement] then  
  Label1.caption = x  
  Label2.caption = x*y  
Else
...  

When I activate the UserForm with these labels from the other one (using UserForm2.Show) the results are Label1 = x, Label2 = 0. But when I try "UserForm2.Show" from the Immediate window, everything works pretty good and I get the correct data.

What am I doing wrong?

The actual code:

If Sheets("SL").Range("B8").Value = True Then
   Label8.Caption = Find_cost(Sheets("SL").Range("b5").Value, Sheets("SL").Range("B4").Value, "ID")
   Label20.Caption = Find_cost(Sheets("SL").Range("b5").Value, Sheets("SL").Range("B4").Value, "ID") * Sheets("SL").Range("b4").Value
Else
   Label8.Caption = "none"
   Label20.Caption = "none"
End If

Where "Find_cost" is a custom function

negas
2#
negas Reply to 2017-12-07 18:27:12Z

Use a userform_initialize event instead of userform_activate. Also, you should save temporary values in variables and debug with breakpoints.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338438 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO