+ Reply to Thread
Results 1 to 4 of 4

Referencing cells in formulas using a defined variable

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2016
    Location
    New York
    MS-Off Ver
    2013
    Posts
    4

    Referencing cells in formulas using a defined variable

    Hi,

    I have the following code
    [code]

    Dim LastRow As Long
    Dim a As Long
    ..
    ..
    ..
    a = [SUMPRODUCT(1/COUNTIF(Sheet1!O2:O5065,Sheet1!O2:O5065))]

    Worksheets("Sheet2").Range("D2").FormulaArray = "=IFERROR(INDEX(Sheet1!$O$2:$O$5065, MATCH(0,COUNTIF($D$1:D1, Sheet1!$O$2:$O$5065), 0)),"""")"

    [\code]

    the variable, LastRow, is the value of last row in my spreadsheet, which is 5065. I was wondering how to replace the 5065 in each of these lines with a reference to the variable, LastRow

    Thanks!!

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Referencing cells in formulas using a defined variable

    Try
    Worksheets("Sheet2").Range("D2").FormulaArray = "=IFERROR(INDEX(Sheet1!$O$2:$O$" & LastRow & ", MATCH(0,COUNTIF($D$1:D1, Sheet1!$O$2:$O$" & LastRow & "), 0)),"""")"
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    08-19-2016
    Location
    New York
    MS-Off Ver
    2013
    Posts
    4

    Re: Referencing cells in formulas using a defined variable

    Thank you so much!!

    Just, how would the replacement work for the first line (a=..)? Because I tried the recommendation you had for the second line, but it didnt work
    Last edited by fox1589; 08-22-2016 at 09:54 AM.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Referencing cells in formulas using a defined variable

    Look at the red font to get it easily
    Worksheets("Sheet2").Range("D2").FormulaArray = "=IFERROR(INDEX(Sheet1!$O$2:$O$" & LastRow & ", MATCH(0,COUNTIF($D$1:D1, Sheet1!$O$2:$O$" & LastRow & "), 0)),"""")"

+ 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. Replies: 4
    Last Post: 12-13-2015, 04:35 PM
  2. Cells with a column defined by variable
    By KOSGH in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2014, 06:30 PM
  3. referencing a defined worksheet variable in a formula in vba
    By framptonl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2012, 08:13 PM
  4. Referencing cells in formulas
    By erik11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2011, 04:10 PM
  5. Referencing Different Formulas from different cells
    By SakebR in forum Excel General
    Replies: 7
    Last Post: 01-27-2011, 08:51 PM
  6. Referencing variable sheet names in formulas?
    By Alabaster in forum Excel General
    Replies: 1
    Last Post: 04-24-2010, 11:20 AM
  7. Referencing defined names in different cells
    By nofzinger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2009, 01: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