+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Squareroot function for a value by macro

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Smile Squareroot function for a value by macro

    Hi, I have a number (e.g) A Column 150, this number multiply by 1.2727 & getting answer we should use SQUREROOT, The answer will be in B Column.This only by macro!
    Last edited by friendlykashish; 06-11-2011 at 12:27 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Squareroot function for a value by macro

    hello

    you can try to use function sqr(value)

    copy below function into module and test it
    Function squre(v As Range) As Double
      squre = Sqr(v.Value * 1.2727)
    End Function
    then put in B1 formula "=squre(A1)"

    it should works

    Best Regards

  3. #3
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    I try, but didn't work


    Quote Originally Posted by maczaq View Post
    hello

    you can try to use function sqr(value)

    copy below function into module and test it
    Function squre(v As Range) As Double
      squre = Sqr(v.Value * 1.2727)
    End Function
    then put in B1 formula "=squre(A1)"

    it should works

    Best Regards

  4. #4
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Squareroot function for a value by macro

    see attached file, I hope it will work

    Best Regards
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    Thanks. But if possible the formula( =squre(A1) directly add into macro.(Not in Excel Column )

    Quote Originally Posted by maczaq View Post
    see attached file, I hope it will work

    Best Regards

  6. #6
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Squareroot function for a value by macro

    it is possible but you have to know a condition which tell to the program when this value should be calculate (for example for any change in sheet1, or when someone select some cell, on workbook open, sheet select, etc,)
    tell me what event will start procedure.

    Best Regards

  7. #7
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    I will clearly explain with excel attachmet. Please find attachment.
    Thanks, Kind Regards,


    Quote Originally Posted by maczaq View Post
    it is possible but you have to know a condition which tell to the program when this value should be calculate (for example for any change in sheet1, or when someone select some cell, on workbook open, sheet select, etc,)
    tell me what event will start procedure.

    Best Regards

  8. #8
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    Sorry, in my reply there is no attachment.
    I will clearly explain with excel attachmet. Please find attachment.
    Thanks, Kind Regards,




    Quote Originally Posted by friendlykashish View Post
    I will clearly explain with excel attachmet. Please find attachment.
    Thanks, Kind Regards,
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-06-2008
    Location
    Canada
    Posts
    141

    Re: Squareroot function for a value by macro

    Sub TryThis()
    With Range("C2", Range("C" & Rows.Count).End(xlUp)).Offset(, 2)
        .FormulaR1C1 = "=Sqrt(RC[-2]*RC[-1])"
        .Value = .Value
        .NumberFormat = "0.00"
    End With
    End Sub
    Put above code in a module in a copy of your workbook and run it.
    See if that is what you want

    Regards.
    John

  10. #10
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    Wonderful & excellent ,this is exactly i expected and one more thing i have some other caluculation in other columns. how to do columnwise calculations. please find attachement in H column! there is list in H 2 column, if i select 10, 100 should come in I 2 column, the same way 11-200, 12-300 ,13-400 respectively.
    Thanks.

    Quote Originally Posted by jolivanes View Post
    Sub TryThis()
    With Range("C2", Range("C" & Rows.Count).End(xlUp)).Offset(, 2)
        .FormulaR1C1 = "=Sqrt(RC[-2]*RC[-1])"
        .Value = .Value
        .NumberFormat = "0.00"
    End With
    End Sub
    Put above code in a module in a copy of your workbook and run it.
    See if that is what you want

    Regards.
    John
    Attached Files Attached Files
    Last edited by friendlykashish; 06-10-2011 at 01:41 AM. Reason: spelling mistake, corrected

  11. #11
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Squareroot function for a value by macro

    Hi friendlykashish,

    In attachment you will find my solution.
    Sensitive for changes on column A & B
    All next data calculate automaticaly.

    Best Regards
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    Excellent.i have some other caluculation in other columns. how to do columnwise calculations. please find attachement in H column! there is list in H 2 column, if i select 10, 100 should come in I 2 column, the same way 11-200, 12-300 ,13-400 respectively.
    Thanks.



    Quote Originally Posted by maczaq View Post
    Hi friendlykashish,

    In attachment you will find my solution.
    Sensitive for changes on column A & B
    All next data calculate automaticaly.

    Best Regards
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Squareroot function for a value by macro

    update code
    Public r As Long
    Private Sub Worksheet_Change(ByVal Target As Range)
    'check if you fill column A & B in current row
     r = Target.Row
    If Target.Column = 1 Or Target.Column = 2 Then
     If Cells(r, 1).Value <> "" And Cells(r, 2).Value <> "" Then
          area = Cells(r, 2).Value / Cells(r, 1).Value / 0.00785 'area
          cons = 1.2727 'const value
          
          Cells(r, 3).Value = area
          Cells(r, 4).Value = 1.2727
          Cells(r, 5).Value = Sqr(area * cons) 'sqrt
          i = i + 1
      End If
      
    ElseIf Target.Column = 8 Then 'change in column H
     If Cells(r, 8).Value > 9 Then
      Cells(r, 9).Value = (Cells(r, 8).Value - 9) * 100
     Else
      Cells(r, 9).Value = ""
     End If
    End If
    End Sub
    Best Regards
    Last edited by maczaq; 06-10-2011 at 07:11 AM. Reason: update

  14. #14
    Registered User
    Join Date
    05-08-2010
    Location
    Qatar
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Squareroot function for a value by macro

    IT'S WORKS GREAT, Please find my attachment for One more modification in H column,
    8, 10,12, 14, 16, 18, 20 ,22, 25, 28, 30, 32, 36, 40 & I column 50.27, 78.54, 113.1, 153.9 201.1 254.5, 314.2, 380.1, 490.9, 615.8, 706.9, 804.2, 1017.4, 1256.6 .

    IF i select 8 in "H" column, 50.27 should come in "I" column. 10 -- 78.5 like this.

    Kind Regards,
    Attached Images Attached Images
    Last edited by shg; 06-10-2011 at 10:42 AM. Reason: deleted quote

  15. #15
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Squareroot function for a value by macro

    here you are
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0