Results 1 to 6 of 6

Thread: Excel

  1. #1
    DavidCobb
    Guest

    Excel

    Hi,

    I'am no good in VBA in Excel. What I need is some VBA that divides a random chosen cell by 3,1415. I want it to be triggered by Ctrl+Alt+P.

    Hope anybody will help. Many thanks!

    best regards, David Cobb

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Excel

    David,

    Do you know that there are (65536 * 256) = 16,777,216 cells in a worksheet !!.

    How many do you propose to use for your project.
    The following code will select a cell at random from a 25 * 25 (=625) grid of cells starting with A1.

    Sub RandomCell()
    Randomize
    Dim rndNo As Long
    Dim lngCellValue As Long
    Dim strCols As String
    strCols = "A1:Y1"
    rndNo = Int(Rnd() * 625)
    Range(strCols).Cells(rndNo).Value = (Range(strCols).Cells(rndNo).Value / 3.1415)
    End Sub

    You can extend the grid by changing "A1:Y1" to whatever range of columns that suits, and also chane the 625 value to the number of cells you require in that column range.

    You can assign your shortcut key manually. If you need any further help let's know.

    Andrew C

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel

    Are you saying that YOU will randomly select a cell and you want to divide that cell by 3.1415 when you press Ctrl+Alt+P? The following will do that:

    <pre>Public Sub DivideByPI()
    ActiveCell.Value = ActiveCell.Value / 3.1415
    End Sub
    </pre>


    You can then assign Ctrl+Alt+P as the macro shortcut key.
    Legare Coleman

  4. #4
    DavidCobb
    Guest

    Re: Excel

    Hi there,

    Both thanks very much. It did what I want it to do.

    So you saw it was PI ;-)

    best regards David

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel

    Well, I think it is really close to PI. I think PI would be 3.14159 which would round to 3.1416 if you want to get picky picky.
    Legare Coleman

  6. #6
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel

    and if you want to get really really picky picky:

    Public Sub DivideByPI()
    ActiveCell.Value = ActiveCell.Value / WorksheetFunction.Pi()
    End Sub

    Brooke

Posting Permissions

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