+ Reply to Thread
Results 1 to 11 of 11

How to create VBA from formula

  1. #1
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    122

    How to create VBA from formula

    I have been trying to a VBA code to place this formula in column BC. =RIGHT(CELL("filename",D2),LEN(CELL("filename",D2))-FIND("]",CELL("filename",D2))).
    Here is what i am trying to use.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: How to create VBA from formula

    I think this may do what you're needing:
    Please Login or Register  to view this content.
    Selecting is frowned on in coding, as there's usually not a need to select.

    For translating a formula to a VBA formula it helps to turn on the Macro recording, then type the formula on your sheet. When you turn off the macro recorder and look at the recorded code the formusa will be in VBA format.
    Last edited by jomili; 06-09-2016 at 04:01 PM.

  3. #3
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: How to create VBA from formula

    Try this?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: How to create VBA from formula

    To expand on jomili's answer.
    For an existing formula:
    Select the cell that has the formula in it
    Tools - Macro - Record or Developer - Record Macro
    OK for Macro Name
    F2
    Enter
    Stop Recording
    If you check your code in the Macro Name you just OK'd, it'll have the formula in code.
    Or
    Select the cell with the formula and in the immediate window type: ?ActiveCell.FormulaR1C1

  5. #5
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    122

    Re: How to create VBA from formula

    Jomili and Cantosh.
    Thanks. Both codes work but only if i run it twice. the first run enters the formula in column BC and the second run enters the sheet name.
    this is not a big problem for me/

    jolivanes
    Thanks for the advice

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: How to create VBA from formula

    Not sure what you're meaning. Is your formula supposed to deliver the sheet name to the BC column? If that's what you're trying to do there are easier ways to do that than the formula method.

    What behavior are you seeing? When you say "the first run enters the formula in column BC" are you saying that at the end of the procedure you're seeing formulas, but no formula results, or are you seeing results of the formulas, and if so is that the result you expected to see, or if not how does it differ from what you expect to see?

    When you run a second time you say "the second run enters the sheet name." where does the sheet name get entered?

  7. #7
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    122

    Re: How to create VBA from formula

    Yes the formula is supposed to deliver the sheet name in column BC.
    When i run the macro it enters the formula in BC. If i run the macro again it replaces the formula with the sheet name in column BC

  8. #8
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: How to create VBA from formula

    Ah, that makes it a lot easier. See if this does the trick:
    Please Login or Register  to view this content.
    If you still need to do that formatting as you like, add the line
    Please Login or Register  to view this content.
    before the "End Sub"
    Last edited by jomili; 06-10-2016 at 09:41 AM.

  9. #9
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    122

    Re: How to create VBA from formula

    That worked great.
    you are awesome

  10. #10
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    122

    Re: How to create VBA from formula

    Thanks Jomili.
    Your help is very much appreciated.

  11. #11
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: How to create VBA from formula

    You're very welcome. Glad I could help.

+ 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. [SOLVED] VBA to create a relative formula in a conditional format (rather than an absolute formula)
    By The_Snook in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2016, 08:00 AM
  2. Replies: 4
    Last Post: 07-16-2013, 10:32 AM
  3. [SOLVED] IF formula- UNABLE TO CREATE CORRECT FORMULA
    By SHEFFCOURT in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 03-04-2013, 02:31 PM
  4. [SOLVED] I want to create a formula in one sheet, that will function as a formula in other sheets
    By johnw993 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-06-2013, 07:07 PM
  5. Replies: 7
    Last Post: 08-22-2005, 08:05 AM
  6. How do I create extractstring formula?-using VLOOKUP formula
    By Vince in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-02-2005, 08:05 AM
  7. Replies: 2
    Last Post: 07-01-2005, 02:05 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