+ Reply to Thread
Results 1 to 14 of 14

Drag formula until column B is blank

  1. #1
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Drag formula until column B is blank

    Can you do a macro that drags a formula from multiple columns until the corresponding cell in column B is blank?

    For example, if I add a row between 14/15, i have to drag all my formulas. What I was hoping to do is identify with the macros which columns have formulas and then when i run it, it drags it down until B is blank. I have formulas starting in row 5 in columns A, C,E,F,G,H,J. I would want it to drag until it hits the first blank cell in column B. is that possible?

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Drag formula until column B is blank

    .

    let C2 Autofill the column C until the last populated cell in column B: .... you can edit the code to fit :

    Please Login or Register  to view this content.
    https://stackoverflow.com/questions/...n-empty-column

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Drag formula until column B is blank

    yes you can, I don't have the code at hand but the quickest way is to record a macro and do just that select the cell in column C and copy it down the last filled row in column B
    stop the recorder and check the code, you van then edit it to do that for columns A, C,E,F,G,H,J. I, you can also edit and union a range and do that.
    You determine the last filled row in column B place this in a variable and use this to limit the copy down.
    If I find the code, I have it in one of my code samples I'll post it later but you can start on this and also past your recorded code and I'll help edit it
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Drag formula until column B is blank

    Not sure, but not working for me.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Drag formula until column B is blank

    The reason I don't want to do a record is because column B is forever expanding. My recorded macro would only go to the cell that i recorded too i believe.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Drag formula until column B is blank

    I found it but you'll need to edit it
    Please Login or Register  to view this content.
    and then more editng

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Drag formula until column B is blank

    That is why i said edit the macro !!!!!

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Drag formula until column B is blank

    .
    Option Explicit

    'paste this in Routine Module
    Sub dragformula()

    With Sheets("Sheet1")
    .Range("C2").AutoFill .Range("C2:C" & .Cells(.Rows.Count, "B").End(xlUp).Row)
    End With

    End Sub


    See attached (NOTE you will need to edit sheet name to fit) :
    Attached Files Attached Files

  9. #9
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Drag formula until column B is blank

    .
    This is not the prettiest method but it works :

    Please Login or Register  to view this content.

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Drag formula until column B is blank

    I modified Logit's code so that it cover all the columns you want

    Please Login or Register  to view this content.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Drag formula until column B is blank

    Just thinking about your question.
    If this is a table you have and you want to copy the formula down when a row is added, you could also convert the range to a table.
    Then all formats, formulas and row banding etc is 'inherited. the moment you add a row or column to the table.
    Checkout working with ListObjects (google for it The Spreadsheet Gurus) , I learned a lot there about Listbojects, makes (Excel) life a whole lot easier when working with table ranges

  12. #12
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Drag formula until column B is blank

    When running this, i'm getting "AutoFill method of Range class failed". Any idea?


    Its flagg on the "C.AutoFill Destination" line.

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Drag formula until column B is blank

    Figured it out, works perfect, thank you.

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Drag formula until column B is blank

    Just for fun, modified it a little on the columns with a yellow header permit values

+ 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. Drag formula to every other column
    By meganob13 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-12-2018, 12:47 PM
  2. [SOLVED] How to drag & skip a column using formula
    By kokjun92 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-03-2016, 05:27 AM
  3. How to drag/fill a column with a 3D formula
    By BG23 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-17-2015, 07:03 AM
  4. Drag formula but skip column
    By ignaciojn in forum Excel General
    Replies: 6
    Last Post: 02-23-2015, 02:11 PM
  5. Help With Correct Drag Formula In Order To Fill Blank Cells
    By Seán_Ireland in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-19-2013, 05:43 PM
  6. [SOLVED] Identify the last filled row in Column A and then drag formula in Column B till the same
    By bonny24tycoon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2012, 10:50 AM
  7. Drag down a formula over blank cells
    By MFT in forum Excel General
    Replies: 6
    Last Post: 05-03-2010, 11:02 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