+ Reply to Thread
Results 1 to 5 of 5

autofill named range after row insert

  1. #1
    Registered User
    Join Date
    12-20-2014
    Location
    West Coast USA (PST/PDT)
    MS-Off Ver
    2016 / o365
    Posts
    36

    autofill named range after row insert

    Hi:

    I'm trying to figure out how to autofill the formulas after inserting a row. I figured out how to copy and insert, however, this keeps the formula the same, instead of the autofill increment.

    This code does the insert/copy with named range "Last_Year":
    Please Login or Register  to view this content.
    I tried removing the .copy and adding a .offset.filldown/fillup but the results were not autofilling.

    I tried adding this after the end With, and although it kind of works, it prompts an object defined error message:
    Please Login or Register  to view this content.
    What I'm trying to do:
    Convert sales data report from 12 month year to 13 periods. Jan-Dec is somewhere in column A, arbitrary row position. "Last_Year" named range refers to only this monthly column range (essentially the "label" for this "table" of data), whatever row it begins (example: A41:A52). Data for each month extends out through each respective row, and this data is formula driven. Manually click-dragging the forumlas completes autofill correctly by incrementing the columns and row numbers.

    After the autofill is done (or before, whatever works better no big deal), I will then iterate through the named range and replace the jan-dec values with P1-P13.

    In the code above, I arbitrarily chose row 3 for the insert.. it doesn't really matter I think where. I have several of these named ranges.

    I hope the above was clear explanation. Thank you for your time.
    Last edited by mynameisnfs; 08-18-2018 at 11:41 PM.

  2. #2
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: autofill named range after row insert

    Hi there
    I am not sure I quote follow what you are actually doing, posting an example, with dummy data where required, often helps.
    The first thing that comes to mind though, have you tried using tables for your data or named range?
    Hope it helps
    Learner, making mistakes, asking daft questions.

  3. #3
    Registered User
    Join Date
    12-20-2014
    Location
    West Coast USA (PST/PDT)
    MS-Off Ver
    2016 / o365
    Posts
    36

    Re: autofill named range after row insert

    Hi there:

    Manually derived example of what I'm trying to do. The named range is A35:A46 in the jan-dec image. My simple code above works fine in the data worksheet, as there are no formulas and the insert preserves the formatting. What you see here is a snip of a report template.
    From this:
    calendar_year.PNG


    To this:
    p13_year.PNG

    I had briefly looked at tables in the past, but they were too challenging to go backwards into the existing templates. The way it works: code iterates through columns of the data worksheet, then makes a copy of the template, and replaces $B in Data!$B## with the respective column.

    What is really weird I went ahead and prepared a working example.. and oddly enough it is doing what I thought it would?!?! I am so confused! Hahaha, sorry to waste your time? I've attached the xlsm, I haven't made a button for the function, it's the "convert" sub.

    I have started research on how to change the range labels from Jan-Dec to P1-P13 and back, I thought it'd be as simple as copying array over, but it's not

    Example:
    p13Array = array("P1", "P2"..."P13")
    Range("Y_Last").RefersTo = p13Array
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-20-2014
    Location
    West Coast USA (PST/PDT)
    MS-Off Ver
    2016 / o365
    Posts
    36

    Re: autofill named range after row insert

    Woohoo, figured out the array to range:

    p13Year = Array("P1", "P2", "P3", "P4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13")
    m12Year = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

    If converting to 13 period, then:
    dataLabel = Application.Transpose(p13Year)

    If converting from 13 to 12, then:
    dataLabel = Application.Transpose(m12Year)

    That application transpose was a booger. Pfffft. Searching how, everyone seems to want to do range to array, had to do it the other way around.

  5. #5
    Registered User
    Join Date
    12-20-2014
    Location
    West Coast USA (PST/PDT)
    MS-Off Ver
    2016 / o365
    Posts
    36

    Re: autofill named range after row insert

    Here it is for anyone interested.. no clue if the way I'm doing this is efficient, but it seems to work.
    Attached Files Attached Files

+ 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] Insert Formula in every second row of named range
    By Decar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-25-2013, 12:12 PM
  2. Insert Row directly below a named range.
    By Baziwan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2013, 10:33 AM
  3. VBA to insert rows in named range only
    By polcen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2012, 11:16 PM
  4. Trouble with autofill of named range
    By ccolton in forum Excel General
    Replies: 5
    Last Post: 02-06-2012, 12:05 PM
  5. Insert a row at the top of a named range
    By K Thomas in forum Excel General
    Replies: 0
    Last Post: 05-03-2011, 10:17 PM
  6. Insert UserForm Data in Named Range
    By Patchworks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2009, 10:50 PM
  7. Using ADO to INSERT Named Range Values into DB
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2005, 07:31 PM
  8. INSERT into named range using ADO
    By Tim Payne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2005, 06:06 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