Results 1 to 4 of 4

How to square a number in VBA excel?

This is a discussion on How to square a number in VBA excel? within the Excel Questions forums, part of the Question Forums category; Hi how to sqUARE A NO. IN vba EXCEL?...

  1. #1
    New Member
    Join Date
    Sep 2006
    Posts
    46

    Default How to square a number in VBA excel?

    Hi how to sqUARE A NO. IN vba EXCEL?

  2. #2
    Board Regular mortgageman's Avatar
    Join Date
    Jun 2005
    Posts
    2,015

    Default

    Not tested, but not much to go wrong with this either

    public function sqnum (num2bsquared as double) as double
    sqnum=num2bsquared * num2bsquared
    end function

    Gene, "The Mortgage Man", Klein
    Gene, "The Mortgage Man", Klein
    See all my Mishegas Videos
    NEW: MY INTERNET RADIO SHOW:
    http://www.blogtalkradio.com/mortgageman

  3. #3
    Board Regular
    Join Date
    Mar 2006
    Location
    UK
    Posts
    974

    Default

    we will need more information on what you are wanting to do,

    like where do you get the number from that you are wanting to SQUARE and where do you want the result to be

    the code using an input and a message box for the result would be#

    Code:
    Sub squre()
    x = 0
    x = InputBox("enter number")
    z = x * x
    MsgBox ("the Squre of " & x & " is " & z)
    
    End Sub
    HTH
    Thanks Shippey

  4. #4
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    26,284

    Default

    .. or perhaps something like this?
    Sub Square()
    ****Selection.Offset(0, 1).Value = Selection.Value ^ 2
    End Sub
    Hope this helps, good luck.
    Peter

    - Read: Posting Guidelines, Forum Rules & FAQs
    - Want to post a small screen shot? Try one of these Excel jeanie, MrExcel HTML Maker or Borders-Copy-Paste (To test: Test Here)
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the VBHTML Maker

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