+ Reply to Thread
Results 1 to 10 of 10

Range Syntax

  1. #1
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Range Syntax

    What is the correct syntax to make this line of code work:

    Please Login or Register  to view this content.
    CtrLastColumn is defined as

    Please Login or Register  to view this content.
    As it is it's giving me an Application-defined or Object-defined error. It is in a With Sheets block.
    Last edited by bishoposiris; 02-28-2014 at 12:15 PM. Reason: Solved

  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: Range Syntax

    Range expects the column letter, not number.

    Try this for the range.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Range Syntax

    Hi bishoposiris,

    I like to use cells in my range instead of letters...

    Say you want to sum from B3 to D7. I like to write this as:
    Range(Cells(3,"B"),Cells(7,"D"))
    See if that works for you.

    Find all the different ways to use Range at:
    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Range Syntax

    .FormulaR1C1 will accept a value, which will be returned by WorksheetFunction.Sum.

    I do not know if OP actually wishes a formula in the cells however.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  5. #5
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Re: Range Syntax

    That's a good point Izandol. The cell has a value in it not a formula. I need to copy the formula all the way down this column (to the last row in the range). How do I do this?

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Range Syntax

    If you know last row:
    Please Login or Register  to view this content.
    Note you may not include CtrLastColumn in SUM or you will have circular reference!

  7. #7
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Re: Range Syntax

    Great! Works as intended. Can you explain how =Sum(RC2:RC[-1]) works? What does RC mean?

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,945

    Re: Range Syntax

    Look at this link to understand R1C1 and A1 convention differences

    http://office.microsoft.com/en-us/ex...005198323.aspx
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Range Syntax

    R = Row
    C = Column
    if you see number in [] it is relative to formula column: C[-1] means one column to left of formula cell. For same row or column you may use only R or C, or R[0] or C[0]

    So RC2 means same row, column 2 (column B) and RC[-1] means same row, one column to left of formula cell.

  10. #10
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Re: Range Syntax

    Great explanation. Thank you!

+ 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. Syntax to set range
    By marlonsaveri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2011, 01:48 PM
  2. Replies: 2
    Last Post: 06-24-2010, 11:44 PM
  3. Syntax of Range
    By avveerkar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2007, 01:46 PM
  4. Syntax help with range
    By ZZBC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2006, 03:35 AM
  5. [SOLVED] Range syntax
    By Dr.Schwartz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2005, 09:05 AM

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