+ Reply to Thread
Results 1 to 6 of 6

How to return a Formula from a Macro?!

Hybrid View

NTB How to return a Formula from... 09-10-2010, 10:09 AM
JBeaucaire Re: How to return a Formula... 09-10-2010, 10:20 AM
NTB Re: How to return a Formula... 09-10-2010, 10:33 AM
snb Re: How to return a Formula... 09-10-2010, 10:59 AM
JBeaucaire Re: How to return a Formula... 09-10-2010, 10:56 AM
NTB Re: How to return a Formula... 09-10-2010, 11:57 AM
  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    How to return a Formula from a Macro?!

    I would like to return this formula

    =IF(G13=0, " ",G13)

    to Range("H21").Value but couldn't

    Please help!

    Thank you.
    Last edited by NTB; 09-10-2010 at 11:57 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to return a Formula from a Macro?!

    The .Value is the problem. You would want to use .Formula.

    Range("H21").Formula = "=IF(G13=0, " ",G13)"
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: How to return a Formula from a Macro?!

    An error is pointing to ",G13)"

    .Formula wouldn't do it.

    Please help !!
    Last edited by NTB; 09-10-2010 at 10:55 AM.

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

    Re: How to return a Formula from a Macro?!

    Range("H21").Formula = replace("=IF(G13=0, # #,G13)","#",chr(34))
    PS. In this forum it isn't necessary to shout for help.



  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to return a Formula from a Macro?!

    Sorry, I copied a little too literally from your post. Better:

    Range("H21").Formula = "IF(G13=0, "" "",G13)"

  6. #6
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: How to return a Formula from a Macro?!

    This works perfectly. Thank you!

    SNB: Thank you for the other code. I'll try it after I'm done with what I am doing.

    Quote Originally Posted by JBeaucaire View Post
    Sorry, I copied a little too literally from your post. Better:

    Range("H21").Formula = "IF(G13=0, "" "",G13)"

+ 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