+ Reply to Thread
Results 1 to 6 of 6

Inserting Variables into Formula Not Working

Hybrid View

  1. #1
    Registered User
    Join Date
    04-05-2024
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    16

    Inserting Variables into Formula Not Working

    I have a macro that will add a formula to a cell and copy it down the column based on several different variables that have all worked great until I get to the formula. I am not sure what is causing it to go wrong. If anyone could help me figure out how to include the LCVPR1 in the formula, that would be great. Maybe I should switch to using relative references?
    Attached Files Attached Files
    Last edited by jonathanramey; 04-08-2024 at 12:48 PM.

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,539

    Re: Inserting Variables into Formula Not Working

    Try changing FormulaArrayR1C1 to FormulaArray.

    Artik

  3. #3
    Registered User
    Join Date
    04-05-2024
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    16

    Re: Inserting Variables into Formula Not Working

    That did not work. Could I have missed something somewhere else? I did try some other things such as having it input a much simpler formula and using Range(LCVPR1 + 1 & "2") instead of Cells and that did not work, which is why I switched, but maybe I am not doing that right? I also have not done a "Dim LCVPR1 As ___" statement, which I am still learning, so maybe that has something to do with it as well? The following line does work, so I am really just unsure as I am still fairly new to VBA.

    Sheets("Vendor Pricing Rules").Cells(1, LCVPR1 + 1) = txtVendorCode

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,046

    Re: Inserting Variables into Formula Not Working

    Maybe
    LCVPR1 = Cells(1, Sheets("Vendor Pricing Rules").Range("J1").End(xlToRight).Column + 1).Address
     Cells(2, LCVPR1 + 1).FormulaArray = "=IF('Input Values'!$L2=" & LCVPR1 & ", IF('Input Values'!$J2="""", """", IF('Input Values'!$P2="""", """", 'Input Values'!$P2)), """")"

  5. #5
    Registered User
    Join Date
    04-05-2024
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    16

    Re: Inserting Variables into Formula Not Working

    This didn't quite work, but I did try adding the +1 to the original "LCVPR1 =" line instead of using it in the formula itself as you did and that made it work. Thank you very much for your help!

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,046

    Re: Inserting Variables into Formula Not Working

    Glad to have contributed.

+ 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] Inserting a formula from a sub that references variables
    By vbalearnerdriver in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2014, 01:12 PM
  2. Trouble inserting SUM function with variables
    By Lewis2010 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2011, 11:54 AM
  3. formula not working because of inserting columns
    By tbag in forum Excel General
    Replies: 0
    Last Post: 04-07-2008, 08:11 AM
  4. Inserting variables within file names
    By kestrel in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-16-2006, 03:10 PM
  5. [SOLVED] Inserting and formating variables in header
    By Strabo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-16-2006, 09:10 PM
  6. Replies: 0
    Last Post: 03-14-2006, 01:10 PM
  7. inserting variables in code????
    By westg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2005, 08:05 AM

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