+ Reply to Thread
Results 1 to 5 of 5

need help understanding this (macro generated) code

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    melbourne australia
    MS-Off Ver
    office 365
    Posts
    41

    need help understanding this (macro generated) code

    Hey all

    Im working on automating a few processes. I consider myself pretty proficient with VBA and can write code from scratch buuuut im also very very very lazy. So one trick i like to do is record a macro, then edit the code to clean it up and add more functionality to it.

    Recently created a macro that creates a new column, adds a vlookup formula to a certain cell and then drags that cell down the column. That formula is as follows "=VLOOKUP(J2, Key!$B$1:$E$50, 3, FALSE)"

    In the VBA that was generated by recording a macro while entering the formula is: ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[5], Key!R1C2:R50C5, 3, FALSE)"

    Just wondering if someone could explain this difference to me? ive never seen this RC[5] or R1C2:R50C5 so im not sure what these mean. Can someone explain how this works? i mean, i understand that RC[5]=J2, but not sure how
    Last edited by beba420; 04-27-2023 at 05:30 PM. Reason: solved :)

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: need help understanding this (macro generated) code

    https://trumpexcel.com/a1-r1c1-refer...third%20column.
    Experience trumps academics every day of the week and twice on Sunday.

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    melbourne australia
    MS-Off Ver
    office 365
    Posts
    41

    Re: need help understanding this (macro generated) code

    aaaaahhhh R is Row and C is column!!! Man im an idiot, that seems so obvious!. Thanks so much for pointing it out

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: need help understanding this (macro generated) code

    Excel has two addressing formats: A1 and R1C1.

    A1 is the default on the worksheets, and gives column letter then row number. All references are relative, unless you use the $ prefix to make it absolute.

    R1C1 gives R then row number, then C then column number. All references are absolute unless you enclose the row or column number in [brackets] to make it relative.

    The link provided by jolivanes is decent but has a major error:
    This is also known as the Relative Notation as the cell reference uses a row number and column number that tells you the relative position of that reference from the active cell.
    This is just wrong. The example that is used for this sentence is absolute notation, and the same article goes on to describe both relative and absolute notation correctly later.

    There are a ton of tutorials on this subject on the web.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: need help understanding this (macro generated) code

    To make it more readable, the code be edited to:
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. Understanding VBA Code
    By Moa88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2019, 08:49 AM
  2. Understanding this code
    By vj2651 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2018, 11:12 PM
  3. Add code in macro generated WB
    By igormigor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2016, 10:44 AM
  4. Macro Help - Update from one Spreadsheet to another, not understanding the code.
    By Dan_Calver in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2015, 07:14 AM
  5. change macro code generated through recording
    By abraham30 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2013, 02:38 AM
  6. Run-time error 1004 on macro generated code
    By BGiffin2004 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2011, 11:01 AM
  7. Tips required to speed up / streamline working code generated by macro recorder.
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2010, 11:24 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