Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

ActiveCell in Excel Trouble - Multiple References

  • 23-11-2010 9:08pm
    #1
    Registered Users, Registered Users 2 Posts: 2,945 ✭✭✭


    Evening all,

    I am currently doing up a spreadsheet to do some data processing and as part of the data processing I am applying filters to the data. The windows of the filters can have variable sizes of say 'n' so I thought it would be best to create a userdefined function of the format "Function UserDefFun(n As Integer)".

    Within my code I access the save the ActiveCell.Row, then I cycle back through "n" rows as part of the windowing process using the offset function. Unfortunately although this works for a single cell, when I place the same function in multiple cells it fails.

    What appears to be happening is that there is a conflict in using ActiveCell.Row many times and as such depending on where I place the cursor when doing "Recalculate All" I get a different answer each time.
    I would be grateful if anyone has an solution to this problem or can point me in the right direction.
    Function GMAUDF(n_days As Integer, alph As Single)
        '
        ' Geometric Moving Average
        '
        Application.Volatile (True)
        Dim tally As Single
        Dim tot As Single
        Dim interm As Integer
        Dim i As Integer
        Dim actrow As Integer
        tally = 0
        tot = 0
        actrow = ActiveCell.Row
        
        For i = 1 To n_days
            interm = -1 * i
            tally = tally + (alph ^ (n_days - i)) * Cells(actrow, 6).Offset(interm, 0)
            tot = tot + alph ^ (n_days - i)
        Next i
        
        GMAUDF = tally / tot
    End Function
    


Comments

  • Registered Users, Registered Users 2 Posts: 2,945 ✭✭✭D-Generate


    And now i remember why it is sometimes best to leave a problem and go back to it.

    I fixed it by just taking the lazy option and throwing in another argument and having that argument being the cell I want to reference for the offsetting.

    Thanks all!


Advertisement