+ Reply to Thread
Results 1 to 28 of 28

Macro For Excel Formula

  1. #1
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Macro For Excel Formula

    Hello Forum,
    I am exploring a possibility to convert the following excel Formula in a valid Macro Procedure
    Please Login or Register  to view this content.
    Attached is the workbook for clarity.Any help will be much appreciated.
    Regards
    Attached Files Attached Files
    Last edited by nuttycongo123; 06-14-2011 at 04:14 PM.
    N

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro For Excel Formula

    Why would you need to convert it? Generally inbuilt functions will be faster than VBA
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Hello Roy,
    Great to see you comment.well the possible answer to your question is as I have to use it again and again and again and the range is dynamic most often .. but still any possibility is welcome

  4. #4
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    ..Learned Forum Members,
    Any help for the query is welcome..

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro For Excel Formula

    Generated via the vba recorder:

    Please Login or Register  to view this content.
    It's the best place I found to convert formulas into vba.

    abousetta

  6. #6
    Registered User
    Join Date
    05-13-2011
    Location
    New Zealander in London
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Macro For Excel Formula

    Quote Originally Posted by nuttycongo123 View Post
    Hello Forum,
    I am exploring a possibility to convert the following excel Formula in a valid Macro Procedure
    Please Login or Register  to view this content.
    Attached is the workbook for clarity.Any help will be much appreciated.
    Regards
    I've updated your spreadsheet with this built in as a Function. There was an anomoly in the 3rd formula where you had "D5>0" instead of "D5<0", other than this, the function performs the same as the first two formula (and the reference on the left).

    You will see how to call this Function in column J.

    This should at least give you the starting point for adjusting it.
    Attached Files Attached Files

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro For Excel Formula

    Please Login or Register  to view this content.



  8. #8
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Valued Members,
    I really appreciate all the responses here ,but can any of you please explain ..
    1/ How to convert this into a macro
    2/ how to run it as a final result ..I have very limited knowledge of VBA..So please explain the intrigues of your code at lenght..You are requested to use the same work book i attached as base.
    Thanks in advance

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro For Excel Formula

    Hi,

    Easiest way I know to convert a formula into a macro is to use the Excel built-in macro recorder. It records the steps you did like a tape recorder would, but instead of recording sounds it records vba steps. You can find it under the Developer Tab.

    Once its recording, put your cursor inside the cell that contains the formula and click enter. WHat you have done is essentially written a formula in Excel and the macro recorder has recorded it as a vba formula.

    Then all you need to do is change the name of the range (in this case the cell) that will contain the formula. For example if you want it in cell I3 then the formula would be:

    Please Login or Register  to view this content.
    look at my previous post for an example of what it looks like.

    Now tarquinious was kind enough to create a usedefined function for you that he named GetValues. This will do all the steps as your formula without requiring you type it in each time.

    I hope this helps.

    abousetta

    P.S. attached is an updated workbook
    Attached Files Attached Files

  10. #10
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Thanks abousetta for your effort ...I really appreciate it ..And as far as tarquinious's function goes it is a fantastique way forward...and I am thankful ..But I was just wondering how to call in that function using a Macro ..I tried couple of things but it seems not to work for me ..Can there be a suggestion for this query using the attached workbook ,in anticipation with best regards

  11. #11
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Anybody who can assist with the request ...

  12. #12
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro For Excel Formula

    Hi,

    I have added another sub that will call the function:

    Please Login or Register  to view this content.
    I have labelled columns I, J and K to reflect where the calculation come from.

    Good luck.

    abousetta
    Attached Files Attached Files

  13. #13
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Can you assist me in making the raange dynamic ,as the data rows and columns vary many a times and then I am stuck .Regards

  14. #14
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Can we do it for dynamic range as well I am attacing the sheet which explains what I mean to say ..
    Attached Files Attached Files

  15. #15
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro For Excel Formula

    Sorry, I don't follow... what do you want done exactly? place formula in every row there is data, or how do you define the range for each sheet?

    Please provide some more details.

    abousetta

  16. #16
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    place formula in every row there is data
    This is what I am looking for .
    Regards
    Last edited by nuttycongo123; 06-11-2011 at 10:49 PM.

  17. #17
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro For Excel Formula

    Maybe something like this:

    Please Login or Register  to view this content.
    abousetta

  18. #18
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Thanks will review and post..
    Last edited by nuttycongo123; 06-12-2011 at 01:39 PM.

  19. #19
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Thank you for the help .This almost works .I will request following change:
    1/ The header "Remarks" to come up (Ref: worksheet in I3 ) with the same format as rest of the cells
    2/ It is not retaining "@" as per the conditions and the formula
    Attached is the worksheet.
    -Regards
    Attached Files Attached Files

  20. #20
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    I am able to get the "Remarks" as the header by using
    Range("AA1", Range("AA" & LastRw)) = "Remarks"
    ,but I am not able to figure out as to how to get the formating..The second query about "@" remains unsolved..

  21. #21
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Any suggestions to get this going ..Shall we consider writing a macro based on the conditions suggested as per the attachment in earlier posts
    Regards
    Last edited by nuttycongo123; 06-13-2011 at 01:26 AM.

  22. #22
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Bump - hoping someone to help.Attaching Worksheet for clarity
    Cross Posted at :
    PHP Code: 
    http://vbaexpress.com/forum/showthread.php?p=244814#post244814 
    Reason I am trying to generate a Macro.I will be obliged if it can be done I will keep the developments posted here as well to avoid contributors from wasting their valuable time if the post is answered.
    Regards
    Attached Files Attached Files

  23. #23
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Bump..hoping to get some help here..

  24. #24
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Almost solved at
    Please Login or Register  to view this content.
    Regards
    Last edited by nuttycongo123; 06-14-2011 at 06:34 PM. Reason: As Suggested by my friend J

  25. #25
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Thank You Simon Llyod for you code

    Credits :In Alphabetical Order
    abousetta,Simon,tarquinious
    Please Login or Register  to view this content.
    Last edited by nuttycongo123; 06-14-2011 at 06:31 PM.

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro For Excel Formula

    Hi N
    Been following this thread...glad you got it resolved. I frankly couldn't figure out what you were trying to do.

    I'd recommend that you please amend your last two posts and use code tags...you used quote tags.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  27. #27
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Quote Originally Posted by jaslake View Post
    Hi N
    Been following this thread...glad you got it resolved. I frankly couldn't figure out what you were trying to do.

    I'd recommend that you please amend your last two posts and use code tags...you used quote tags.
    Thanks J ,I edited as recommended.. I am glad that the contributors were able to assist me One does bump into nice people like you once in a while who are selfless and kind enough to assist you..
    Regards

  28. #28
    Forum Contributor nuttycongo123's Avatar
    Join Date
    01-26-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Macro For Excel Formula

    Here is one more beautiful solution suggested by my friend tarquinious,it's worth a study for it's simplicity and compactness.
    Please Login or Register  to view this content.
    Please modify it as per your need ..as he explains further
    it will be easier for to add your own different criteria into the macro if you like. Just follow the same format as the other groupings.
    Regards
    Last edited by nuttycongo123; 06-14-2011 at 08:15 PM.

+ 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