Where did I go wrong? - Simple userform code

MrDoc

Active Member
Joined
Jul 30, 2002
Messages
343
Hello,

When I click spinbutton1 this error happens:
"Method range of object _global failed"
The error occurs in the line 'Range("I5")..... '
Private Sub SpinButton1_Change()
TextBox1.Value = SpinButton1.Value
Range("H5").Value = SpinButton1.Value
Range("I5").Value = TextBox1 * Range("fds") * Range("verm") * Range("cdia")

What is wrong with the code? Please help!
Best Regards,
MrDoc
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I would start by substituting literal range references for the "range variables" you have......not exactly sure what you are doing there; maybe it works, and I am just ignorant of that syntax.


So, if "cdia" refers to "F5", use "F5" while troubleshooting your code.

I would also suspect that the ranges you are using as numbers may not be perceived as numbers. That should come back as Type Mismatch, shouldn't it?

The biggest issue I take with your code is anyone who might be at your side would first have to rewrite the code into less complex statements.

Are you sure that TextBox1 is being handled as a number?
Those range variables/literal strings, have you seen that construct used elsewhere? I haven't.
This message was edited by stevebausch on 2002-12-23 20:39
 
Upvote 0
You have a syntax logic error.
Your last line of code:

Your TextBox1 should be TextBox1.Value and it may need to be converted to numeric data to do math on it. Also, you canot operate on ranges, unless your named ranges are single cells. JSW
 
Upvote 0
Hi,

Thanks for replying. I found this solution:

Private Sub SpinButton1_Change()
TextBox1.Value = SpinButton1.Value
Range("H5").Value = SpinButton1.Value
Range("I5").Value = SpinButton1.Value * Sheets("Dados").Range("fds") * Sheets("Dados").Range("verm") * Sheets("Dados").Range("cdia")
End Sub

It works now, and yes, range names are single cells here.

Best Regards and Merry Christmas to all.
 
Upvote 0

Forum statistics

Threads
1,214,868
Messages
6,122,005
Members
449,059
Latest member
mtsheetz

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