+ Reply to Thread
Results 1 to 9 of 9

Help

  1. #1
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241

    Help

    I am trying to write a code to calculate efficiency of a process. The following code gives me "Object Required' Error Please educate me.

    Private Sub CommandButton1_Click()
    Dim NetLoad As Variant
    Dim AveCoatWt As Variant
    Dim WtGain As Variant
    Dim solutionapplied As Variant

    NetLoad.Value = TextBox1.Text

    AveCoatWt.Value = TextBox2.Text
    WtGain.Value = TextBox3.Text
    solutiionapplied.Value = TextBox4.Text
    TextBox5.Value = (TextBox4 / ((TextBox1 * TextBox2 * 1000000) * TextBox3))


    End Sub

    Thank you for your help.
    Syed

  2. #2
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    just a quick observation:

    Dim solutionapplied As Variant

    solutiionapplied.Value = TextBox4.Text

    are different. Typo in "solutiionapplied...."???
    and because you don't define "solutiionapplied" you get the stated error?

    Good luck
    Bruce
    The older I get, the better I used to be.
    USA

  3. #3
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241
    Thank you Bruce for correction of typo. That did not helped.
    How should I define solutionapplied?
    Thanks
    Syed

  4. #4
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241

    Can anyone help please?

    Please see my original post.
    Thank you
    Syed

  5. #5
    Dave Peterson
    Guest

    Re: Help

    You declared these things:

    Dim NetLoad As Variant
    Dim AveCoatWt As Variant
    Dim WtGain As Variant
    Dim solutionapplied As Variant

    But you never set them to anything.

    What are they?

    saziz wrote:
    >
    > I am trying to write a code to calculate efficiency of a process. The
    > following code gives me "Object Required' Error Please educate me.
    >
    > Private Sub CommandButton1_Click()
    > Dim NetLoad As Variant
    > Dim AveCoatWt As Variant
    > Dim WtGain As Variant
    > Dim solutionapplied As Variant
    >
    > NetLoad.Value = TextBox1.Text
    >
    > AveCoatWt.Value = TextBox2.Text
    > WtGain.Value = TextBox3.Text
    > solutiionapplied.Value = TextBox4.Text
    > TextBox5.Value = (TextBox4 / ((TextBox1 * TextBox2 * 1000000) *
    > TextBox3))
    >
    > End Sub
    >
    > Thank you for your help.
    > Syed
    >
    > --
    > saziz
    > ------------------------------------------------------------------------
    > saziz's Profile: http://www.excelforum.com/member.php...fo&userid=6350
    > View this thread: http://www.excelforum.com/showthread...hreadid=477205


    --

    Dave Peterson

  6. #6
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241
    Hi Dave,
    The values for those are being input through textboxes.
    Syed

  7. #7
    Dave Peterson
    Guest

    Re: Help

    Then those things are just holders for the values from the textboxes?

    If yes, then each of those things will hold a string -- until/unless you convert
    it to something else. And since you're doing arithmetic with them, maybe...

    Private Sub CommandButton1_Click()
    Dim NetLoad As double
    Dim AveCoatWt As double
    Dim WtGain As double
    Dim solutionapplied As double

    NetLoad = cdbl(TextBox1.Text)
    AveCoatWt = cdbl(TextBox2.Text)
    WtGain = cdbl(TextBox3.Text)
    solutionapplied = cdbl(TextBox4.Text)

    TextBox5.Value = (TextBox4 / ((TextBox1 * TextBox2 * 1000000) * TextBox3))

    End Sub

    These are simple variables--not objects (like ranges, which have a .value
    property).

    saziz wrote:
    >
    > Hi Dave,
    > The values for those are being input through textboxes.
    > Syed
    >
    > --
    > saziz
    > ------------------------------------------------------------------------
    > saziz's Profile: http://www.excelforum.com/member.php...fo&userid=6350
    > View this thread: http://www.excelforum.com/showthread...hreadid=477205


    --

    Dave Peterson

  8. #8
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241
    Dave,
    Thank you for the help.
    What could be the format for % for textbox5 value?
    I am trying this:
    textbox5.text=format( formula, "%")
    It gives me error.
    Thnaks once again for your help.
    Syed

  9. #9
    Dave Peterson
    Guest

    Re: Help

    Maybe...

    textbox5.text=format( formula, "0.00%")

    And you may not need those intermediate variables, too:

    Option Explicit

    Private Sub CommandButton1_Click()

    TextBox5.Value _
    = Format((Me.TextBox4.Value _
    / ((Me.TextBox1.Value * Me.TextBox2.Value * 1000000) _
    * Me.TextBox3.Value)), "0.0%")

    End Sub

    But I would add some checks for numbers for each of those textboxes.

    saziz wrote:
    >
    > Dave,
    > Thank you for the help.
    > What could be the format for % for textbox5 value?
    > I am trying this:
    > textbox5.text=format( formula, "%")
    > It gives me error.
    > Thnaks once again for your help.
    > Syed
    >
    > --
    > saziz
    > ------------------------------------------------------------------------
    > saziz's Profile: http://www.excelforum.com/member.php...fo&userid=6350
    > View this thread: http://www.excelforum.com/showthread...hreadid=477205


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1