+ Reply to Thread
Results 1 to 16 of 16

Formula in macro not working

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Formula in macro not working

    Hi.
    Can anyone fix this formula I have in the macros so that it can work properly?

    This is the outcome I want the formula below to do: In the 2nd to last column, starting from the 18th row, I would like to multiply the 3rd to last column by the value in cell A1.

    Please Login or Register  to view this content.
    Any help would be greatly appreciated.

    Thank s in advance.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula in macro not working

    Hi,

    Untested but try

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    note the double quotes....
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Thanks.
    I tried the code but the 'formula bar' in the spreadsheet shows this =(A1*"&Range(Cells(18, lc - 3), Cells(lr - 1, lc - 1))") and the relevant cell shows this #VALUE!

  4. #4
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Also, I can get this formula to work if I use the R1C1 method but the problem with this is that cell A1 (which has the value I want) changes to ascending cells (A2, A3, A4 A5 etc) when the formula is dragged down the cells.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula in macro not working

    Hi,

    Looking more closely you appear to be trying to incorporate VBA syntax in and Excel formula.

    Upload your workbook and manually add some typical results. Explain in a note where the results are how you have calculated them.

  6. #6
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Sure. Copy of Row Columns.xlsm

    Thanks.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula in macro not working

    How are you calculating cost? Please give specific cell references.

  8. #8
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    I'm calculating the retail multiplied by the percent off the retail. So in this example the client is getting 70% off the retail therefore I multiply the retail by 0.3 which is found in cell A1. The cost will differ with each invoice.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Formula in macro not working

    Maybe:

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Thanks, that worked but how can I get this cell to show the formula that's in it as opposed to just the values?

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula in macro not working

    In that case...

    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Thank you but your code works only if I keep the columns as is, however, I want to work with the last column being unknown since I may insert columns or take away columns for all my invoices.

  13. #13
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Your code really works for the original question I asked. Thank you for your time. This thread is solved.

  14. #14
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula in macro not working

    Hi,

    See attached.

    My preferred method for this sort of stuff is to hold any master formula on the sheet and copy them as appropriate. Here I've used a new hidden row 1.

    And specifically identifying the last column with a range name is to be preferred since the used range property is not particularly safe. For instance entering a value past the end column of the invoice and then deleting it changes the used range until you subsequently save the workbook.

    So the attached uses range names and the following macro

    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    That's another approach but it worked great!
    Thank you for you efforts

  16. #16
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Formula in macro not working

    Hi. Didn't realize I can continue posting on a thread that I marked as solved.
    Can you help me with this issue?


    The code below inserts a formula into the given cell resulting in "=E18*$A$1" where "A1" = the cost of the customer, see attachment: Copy of Row Columns.xlsm

    Is there a way to modify this section of the code only (see below) where the result of the cell will return "=E18*0.3"? Now obviously I can enter "0.3" into the macro but the value in A1 will always change with every invoice, so the code needs to be flexible.

    Please Login or Register  to view this content.

+ 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] Formula not working within macro
    By theletterh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-13-2013, 12:32 PM
  2. [SOLVED] Formula not working when put inside VBA macro
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2013, 10:00 AM
  3. formula is not working in macro
    By Jamnes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2012, 10:32 AM
  4. Formula to cell with macro not working
    By tneva in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2009, 09:26 AM
  5. [SOLVED] Macro formula using MYDATE not working
    By Bricktop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2005, 03: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