+ Reply to Thread
Results 1 to 9 of 9

How to use formulas in vba

  1. #1
    Registered User
    Join Date
    03-19-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    49

    How to use formulas in vba

    Hello,

    I am trying to use vba to autofill formulas down columns. Here's what I have:
    Please Login or Register  to view this content.
    vba doesn't like the use of quotes within the formulas, like "shipment". However it doesn't work to remove the quotes either. I'm not even sure if using =IF in those formulas will work since vba has its own version of IF statements. Those formulas work fine within a cell on a worksheet. Can anyone help with how to enter those formulas in vba?

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to use formulas in vba

    Try this.
    Please Login or Register  to view this content.
    By the way, you could use TEXT(A2, "mmmm") instead of CHOOSE(...).
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to use formulas in vba

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to use formulas in vba

    Use two quotes to represent one literal quote within a string.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Registered User
    Join Date
    03-19-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    49

    Re: How to use formulas in vba

    Thank you all for your replies! I didn't receive an email notification so I wasn't aware until now that I had received any replies.

    I'll need to go back in and look at this method again, I ended up using array formulas on my sheet instead of trying this with vba. However, I had tried the two quote method after posting my original question but to no avail. I don't recall receiving any errors in vba but it just didn't autofill any of the formulas. Are those formulas maybe too complex for use in vba as string formulas? I was able to make it work using simple formulas like =A+B.

    Thanks!!!

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to use formulas in vba

    Quote Originally Posted by indub View Post
    I had tried the two quote method after posting my original question but to no avail.
    Your original code calculated the LastRow incorrectly. Try the code below.
    On another note; I used an alternate formula for the Text-Month.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 12-09-2015 at 08:12 PM. Reason: Sheet17

  7. #7
    Registered User
    Join Date
    03-19-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    49

    Re: How to use formulas in vba

    Thanks! I made those changes and decided to go with this vba option over the arrays I was using. It still wasn't working at first and I was scratching my head, turns out I do need the double quotes and also needed to remove the With/End With statement. There was no reason for it. Working well now!
    Please Login or Register  to view this content.
    I actually have 10+ formulas in my code but those examples above were enough to explain my question. Thanks again for the help!



    What can I add into either that code above or the workbook itself to make it execute automatically instead of using a command button? Should I start a new thread for that question?
    Last edited by indub; 12-10-2015 at 01:50 PM.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to use formulas in vba

    Quote Originally Posted by indub View Post
    Thanks again for the help!

    What can I add into either that code above or the workbook itself to make it execute automatically instead of using a command button? Should I start a new thread for that question?
    You're welcome.

    You could start a new thread and explain what you mean by automatically. What's the trigger? Excel doesn't read minds.

  9. #9
    Registered User
    Join Date
    03-19-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    49

    Re: How to use formulas in vba

    It wasn't as difficult as I thought it would be. I used column A as the trigger so any time a cell in column A changes it'll update.
    Please Login or Register  to view this content.
    Not sure if there's a better way to do that but it seems to work for my needs. Thanks again!

+ 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. Poll on - Lots of simple formulas vs fewer but more complex formulas
    By gassiusmax in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-20-2014, 08:51 PM
  2. Using Cell references in file paths for formulas to create dynamic formulas
    By MichaelStokesJr in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-04-2013, 11:49 AM
  3. Insert cells, fill formulas down, set formulas for dynamic range
    By Snickers65 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2013, 01:43 PM
  4. Replies: 5
    Last Post: 09-25-2013, 02:51 PM
  5. [SOLVED] VBA to enter various formulas every 10 rows and show dynamic formulas not values
    By faby2203 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-04-2013, 07:05 AM
  6. Help modifying macro to wrap iferror formulas around existing formulas
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:04 PM
  7. Replies: 5
    Last Post: 05-05-2008, 02:22 PM

Tags for this Thread

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