+ Reply to Thread
Results 1 to 16 of 16

Formula in macro not working

Hybrid View

  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.

    Dim lr As Long
    Dim lc As Long
    
    lr = ActiveSheet.UsedRange.Rows.Count - 2
    lc = ActiveSheet.UsedRange.Columns.Count
    
    Range(Cells(18, lc - 1), Cells(lr - 1, lc - 1)).Formula = "=(a1*"&Range(Cells(18, lc - 3), Cells(lr - 1, lc - 1))")"
    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
    Range(Cells(18, lc - 1), Cells(lr - 1, lc - 1)).Formula = "=(a1*""&Range(Cells(18, lc - 3), Cells(lr - 1, lc - 1))"")"


    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
    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.

  5. #5
    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.

  6. #6
    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.

  7. #7
    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.

+ 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. 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