+ Reply to Thread
Results 1 to 4 of 4

Macro only calculates on whole numbers!! im sure this is a rookie mistake.

  1. #1
    Registered User
    Join Date
    08-28-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    4

    Macro only calculates on whole numbers!! im sure this is a rookie mistake.

    I'm doing a few things here at it is my second day of using macros so im sure there is better ways of doing this. Anyway the problem is that it doesnt calculate the correct percentile look towards the bottom of the macro the range is made up of decimal values (0.323, 0.421). I need to calculate the percentile of values from a data logger so there are lots of them.

    Thanks alan

    Sub Calculate95anodiclines()


    'initialise rngdata for range to be selected and perc for hopefully more stable version of rngdata and hope for initial selection as Range type variable
    Dim rngdata As Range
    Dim perc As Range
    Dim Hope As Range

    'initialise what wil become anodic and cathodic lines
    Dim Anodic As Long
    Dim Cathodic As Long

    'set hope to initial selelction maybe a good idea for future macros
    Set Hope = Selection

    'initialise x as long
    Dim x As Long

    Dim y As Long

    'set initial value of x and ythis is based on using relative cell refernces in appropriate column for do while loops
    x = 0

    y = 0

    'sets instructions based on the active cell not being blank
    Do While ActiveCell.Value <> ""

    'increases value of x by as x is going to be used to define selection
    x = x + 1

    ' advances to the next cell
    ActiveCell.Offset(1).Select

    Loop

    'defines range data relative to x and active cell
    Set rngdata = Range(ActiveCell.Offset(-x), ActiveCell.Offset(-1))

    'Selects range rng data
    rngdata.Select

    'defines new range perc as equal to rng data hopefully will not change as x changes or something
    Set perc = Selection

    'calculates 95% anodic and cathodic vaues
    Anodic = Application.WorksheetFunction.Percentile(perc, 0.95)
    Cathodic = Application.WorksheetFunction.Percentile(perc, 0.95)[/B][/B]



    'sets instructions based on the active cell not being blank, ie percentile and -850 columns extended while there is a datalogged value
    Do While ActiveCell.Value <> ""


    ' offsets anodic and cathodic values by 3 and 4 columns
    ActiveCell.Offset(0, 3).Range("A1").Select
    ActiveCell.FormulaR1C1 = Anodic

    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = Cathodic

    'inserts an -850 value ready for extension with other three values to form series for graph
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = -850



    ' increments y count to advance to the next cell

    y = y + 1

    Hope.Offset(y, 0).Range("A1").Select


    Loop

    MsgBox "Bibbity Bobbity"

    End Sub

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Macro only calculates on whole numbers!! im sure this is a rookie mistake.

    Try using Double Data type instead of Long.

    Deep
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    08-28-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro only calculates on whole numbers!! im sure this is a rookie mistake.

    Bonza works perfect ! now onto the next step.

    Many Thanks

    Alan

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Macro only calculates on whole numbers!! im sure this is a rookie mistake.

    Glad it helped!

    Mark the thread solved if you have received a satisfactory solution.

    Cheers!

    Deep

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Rookie needs some vba and/or macro help please!!!
    By johnsmithuk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2013, 03:25 PM
  2. Help rookie here need macro reverse word order
    By MikeKasmeier in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-13-2009, 12:08 PM
  3. macro mistake
    By nhughes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2007, 01:20 PM
  4. [SOLVED] Mistake of changing decimal into whole numbers
    By Roberta in forum Excel General
    Replies: 2
    Last Post: 12-29-2005, 11:10 AM
  5. [SOLVED] Rookie needs a macro
    By Denise in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-25-2005, 05:06 PM

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