+ Reply to Thread
Results 1 to 6 of 6

Macro to write Formula to cells

  1. #1
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Macro to write Formula to cells

    I am tiring to have a macro write a list of Formulas to cells and when I run it I get a Debug Error. What is wrong with my code?
    Please Login or Register  to view this content.
    Last edited by CityMPLSEmpolyee; 06-10-2011 at 10:42 AM.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Macro to write Formula to cells

    I know what's happening. I'm not sure what the fix is outside of changing your formulas. VBA is seeing your second " as the end of the formula

    Please Login or Register  to view this content.
    If you replace your "" with 0 for example
    Please Login or Register  to view this content.
    It works fine.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro to write Formula to cells

    Thanks, that works.
    But why is it that we can't enter in a blank through the macro, when in the cell I can write the Formula to enter blank?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro to write Formula to cells

    Hi,

    My rule is when trying to convert an Excel formula to a VBA formula in the .Formula = line is to double every quote mark after putting a Quote at the front and end of the Excel Formula.
    Example: A cell formula of:
    Please Login or Register  to view this content.
    Changed to a VBA formula looks like this:
    Please Login or Register  to view this content.
    Put quotes in front of the equal sign and at the end and double every quote in between.

    I think you will see that the """" will turn into a "" after the code is run. This would be the blank you are looking for.

    Hope this helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro to write Formula to cells

    ChemistB
    I found your post
    "Inputting a formula which contains Quotes" this was the way I should have posted it
    read the replay you got, and that works as will,
    when I tried it I put in too many ".
    your help was great, Thanks

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Macro to write Formula to cells

    Glad I could help (Indirectly). I reposted myself because I was definitely interested in a solution. We both learned something.

+ 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