+ Reply to Thread
Results 1 to 17 of 17

Macro and Calculation.

  1. #1
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Macro and Calculation.

    I am not that familiar with Excel, but i want to make a Macro, and perhaps a calculation of the results i will be getting in a function (if possible).

    So here is a file:

    Now the function i want to do is:
    "X" = From Row 2, till the the last row before it goes blank (don't know if this is possible, currently i have to scroll and write manually).

    LINEST(C2:C"X",A2:A"X",TRUE,FALSE)
    Give me the 2 answers, donīt know how it can be give, if i can get it written or something would be nice.


    LINEST(H2:H"X",G2:G"X",TRUE,FALSE),1)


    If this is possible, it would save alot of time. And then i would also try to give the calculation of the results a try, though i doubt it's possible, but then again, i am not familiar with Excel.
    Last edited by zerowalker; 06-08-2013 at 12:08 PM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Macro and Calculation.

    Post an excel file, without confidentional information.

    Please also add the desired (expected) result.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Macro and Calculation.

    the following line in VBA will place the result of linest in a1

    the trick is to identify the last non-blank cell in the row: it is range("B2").end(xlup)

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    What do you mean, Confidental information??

    Here it is: http://www.sendspace.com/file/268ir5

    And for the result, on this file i am expected to get:


    =LINEST(C2:C46822,A2:A46822) = 33.4736187211877 , 67.8567627719...

    =LINEST(H2:H3135,G2:G3135) = 0.0026042210295967 , 12.80325929


    rcm: VBA?
    Do you mean Visual Basic Scripting?

    I am as said, not familiar, care to point me in the right direction?

    EDIT:

    Okay found the VBA thing, but i seen to get an error when i try this:

    Cells(1, 1) = Application.WorksheetFunction.linest(Range("B2", Range("B2").End(xlup)), Range("c2", Range("c2").End(xlUp)), True, False)

    It says "invalid outside procedure", and sadly, that doesn't tell me anything.

    EDIT 2:

    OKay think it was becuse i ran the script on the script manager, instead of in Excel, not i get another error though, but atleast it seems to run.
    Last edited by zerowalker; 06-08-2013 at 01:00 PM.

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Macro and Calculation.

    Sorry i'm not familiar with formulat linest.

    Maybe another one will step in to give an solution.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro and Calculation.

    Name Manager > New, Name: x, Refers to: ='test test for sync'!$A$2:INDEX('test test for sync'!$A:$A, MATCH(9E+307, 'test test for sync'!$A:$A))

    Name Manager > New, Name: y, Refers to: ='test test for sync'!$C$2:INDEX('test test for sync'!$C:$C, MATCH(9E+307, 'test test for sync'!$C:$C))

    Select two cells and array-enter =LINEST(y,x)

    You'll have to save the workbook as an xlsx to preserve the names.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    It seems that the VBA doesn't work when trying to detect the entire row Excluding blank cells, if i write manually it works.

    Name Manager > New, Name: x, Refers to: ='test test for sync'!$A$2:INDEX('test test for sync'!$A:$A, MATCH(9E+307, 'test test for sync'!$A:$A))

    Name Manager > New, Name: y, Refers to: ='test test for sync'!$C$2:INDEX('test test for sync'!$C:$C, MATCH(9E+307, 'test test for sync'!$C:$C))

    Select two cells and array-enter =LINEST(y,x)

    You'll have to save the workbook as an xlsx to preserve the names.
    I did this, and i get "1" as an answer:S

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro and Calculation.

    I did this on the csv file you posted without difficulty; there were no blanks.

    It can be done with blanks, but it's very messy. I suggest you compact your data to eliminate them.

  9. #9
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    Hmm wierd, will try again.

    But i got a function working a bit:

    Sub sync()
    a = Application.WorksheetFunction.LinEst(Range("C2", Range("C2").End(xlDown)), Range("A2", Range("A46822")), True, False)


    Cells(11, 11) = a
    End Sub


    The thing though, i tried calculating, for example

    u = a*a

    but that doesn't work, but other stuff work (11+42 etc), i get Type Mismatch.

    Also, is it possible to get the entire number, cause it seems to limit it down for some reason (i want all decimals).

  10. #10
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    Okay i have been able to get a function that does mostly what i intended.
    But there seems be be some limitations.

    First, it seems to truncate the calculations, making them less accurate.
    Second, i can't use the macro/vba on what i want, itīs stored in a certain file that i must have opened (not familiar with this, so have no idea what to do here).

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro and Calculation.

    Okay i have been able to get a function that does mostly what i intended.
    What function?
    Second, i can't use the macro/vba on what i want, ...
    Why not?

  12. #12
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    The function i want.

    I calculate everything, relative rates and the correction factor.

    But i have problem. Linest has 2 results, but only 1 is shown in the formula.
    Anyway i can display the other result?


    I solved the problem with the Macro not working on everything.
    Or well, maybe not solved it. But i save the xmls file, and have it in my "Macro" folder.
    I would however rather have it activated all the time, instead of having to open the xmls every time.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro and Calculation.

    If you would POST your code, I'd make a suggestion.

  14. #14
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    Here it is, a bit messy though:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro and Calculation.

    Please Login or Register  to view this content.
    Last edited by shg; 06-08-2013 at 06:30 PM.

  16. #16
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    Awesome!

    Now the thing left is.

    I want to have 2 check boxes, and i want one to be checked as default, and if i check the other, a value will differ.

    Please Login or Register  to view this content.
    bit is that value.

    I can change it with a checkbox easily, But the problem is, the data doesn't refresh.
    I donīt know how to make it refresh when the value changes.


    EDIT:

    Okay i am totally lost on this, i search and search but i donīt seem to be able to do what i want to do.

    I simply want to have 2 checkboxes,(OptionButton), and if i check one, a variable will change, and if i check the other it will change to something else.
    A = 2 if OptionButton1 is checked, for example.

    But the problem is, even if i set something like that, i donīt know how to make it update the information, for example

    Texboxt1 = U *553 / A

    So if i change the checkbox, The value of Textbox1 will change.

    Hopefully you understand, i am not that good at explaining, but itīs fairly easy what i am trying to do.

    EDIT 2:

    Just because of that, i actually solved it;P
    Last edited by zerowalker; 06-09-2013 at 01:17 AM.

  17. #17
    Registered User
    Join Date
    06-08-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    20

    Re: Macro and Calculation.

    Is it possible to save the Linest x and y results in a variable?
    As currently itīs written into a cell, and then read from there, which is a bit unoptimized.
    I would like to save it in a variable.

    Also does the Macro have to been in a .xlsm file?

    Cause itīs just irritating that when i open a Excel file and want to use the macro, i have to open that Excel file, which brings up window with cells and all that stuff,
    I would like the macro to just be there, and if i run it, it will use the active worksheet.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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