+ Reply to Thread
Results 1 to 4 of 4

Need Relative Reference in VBA/Macro for Autofill

  1. #1
    Registered User
    Join Date
    05-18-2018
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    11

    Need Relative Reference in VBA/Macro for Autofill

    The VBA code below is my attempt at automating what should be a few simple steps in an inventory spreadsheet.
    The step I am stuck at is how to autofill the 2 new columns based on the formulae copied from the columns on the right.
    I need to figure out a way to reference the new columns without designated specific column labels because 2 new columns are added every week, both in this part of the spreadsheet and just after Column G (not shown). It would be nice to autofill both columns in one step, but ultimately as long as the autofill is accomplished, I don't really care what it takes.

    I read through this thread: [SOLVED] Relative Reference and AutoFill- Macro. It was somewhat helpful, but I could not adapt it enough to what I need.

    ________________________________________________________
    Please Login or Register  to view this content.
    _______________________________________

    Any and all help is greatly appreciated.
    Attached Images Attached Images
    Last edited by Leith Ross; 05-18-2018 at 05:18 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need Relative Reference in VBA/Macro for Autofill

    Please Login or Register  to view this content.

    This is based on

    Please Login or Register  to view this content.
    Which can be written:

    Please Login or Register  to view this content.
    'Cells(Row, Column), So cells(1,1) = "A1", cells(1,2) = "B1"

    The beauty of this method is that you can easily loop through a range of Cells.

    Please Login or Register  to view this content.



    I know, that is a stupid and slow example.

    This would be faster:=

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 05-18-2018 at 05:42 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    05-18-2018
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    11

    Re: Need Relative Reference in VBA/Macro for Autofill

    Hello mehmetcik, thank you for your expedient reply to my open question. I have a couple questions. Does this solution set the autofill to go all the way to the end of the end of the data down the 2 columns? I admit I know barely anything about how to read code, but it looks like it would just autofill down to 20 rows. Also, I see the 'copy' function in your solution, but I didn't see an autofill function called anywhere. Please forgive me my lack of understanding, it's just not plain to me, and I want to make sure I implement this code correctly. I'm assuming when you use the terms A and B for column references, that's merely a placeholder for whatever column I need to implement this for. I appreciate the time you've taken to help me on this.

    Respectfully,
    DV

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need Relative Reference in VBA/Macro for Autofill

    The copy function will copy your formulas so why go the autofill route?

    If you want to fill down to the bottom of your data then replace the 20 with your last row.

    So how do you find your last row?

    Please Login or Register  to view this content.
    This returns the row number of the last used cell in column34. ie Column AH

    So:-

    Please Login or Register  to view this content.

    Or For your immediate need:-

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 05-21-2018 at 05:52 PM.

+ 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. autofill with relative reference
    By bimo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2014, 06:15 AM
  2. Replies: 0
    Last Post: 09-17-2012, 08:24 AM
  3. Using relative reference in macro
    By Bas in forum Excel General
    Replies: 0
    Last Post: 03-23-2006, 08:15 AM
  4. [SOLVED] Relative Reference and AutoFill- Macro
    By Andy Roberts in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-27-2005, 11:05 PM
  5. [SOLVED] Macro-Relative Reference
    By Baldeagle in forum Excel General
    Replies: 2
    Last Post: 07-13-2005, 01:05 PM
  6. [SOLVED] Relative reference autofill increment other than +1
    By SteveB in forum Excel General
    Replies: 3
    Last Post: 06-14-2005, 03:05 PM
  7. [SOLVED] Relative reference in macro
    By Ricki Miles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2005, 05:06 PM

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