Results 1 to 4 of 4

Where did I go wrong? - Simple userform code

This is a discussion on Where did I go wrong? - Simple userform code within the Excel Questions forums, part of the Question Forums category; Hello, When I click spinbutton1 this error happens: "Method range of object _global failed" The error occurs in the line ...

  1. #1
    Board Regular
    Join Date
    Jul 2002
    Location
    Portugal
    Posts
    343

    Default


    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

  2. #2
    Board Regular
    Join Date
    May 2002
    Posts
    810

    Default

    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 ]

  3. #3
    MrExcel MVP Joe Was's Avatar
    Join Date
    Feb 2002
    Location
    Central Florida, USA
    Posts
    7,539

    Default

    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

  4. #4
    Board Regular
    Join Date
    Jul 2002
    Location
    Portugal
    Posts
    343

    Default

    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.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com