+ Reply to Thread
Results 1 to 7 of 7

Macro to find the first blank cell in a column and add formula till lastused row

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2018
    Location
    canada
    MS-Off Ver
    2016
    Posts
    4

    Macro to find the first blank cell in a column and add formula till lastused row

    Apologies as I am pretty sure this was asked before , but I couldn't find the correct thread. I am new to VBA so could be that I am not searching properly.

    I have a worksheet that uses column A to DD. I have a task(outside of excel) that find the last used row in this worksheet and paste data daily, except for the last 2 columns. Last two rows have formula which is noted below. I am looking for a macro that can autofill the blank cells in each column with below formula. I prefer the macro to paste the formula only from blank cell down, rather than from cell CZ2 and CY2 onwards.

    Column CZ formula is INDEX(Categories,MATCH(TRUE,ISNUMBER(SEARCH(Keywords,I2)),0))
    Column CY formula is =IF(LEFT(S2,3)="rem","Ignorefromanalysis",W2)

    There are no blank cells in Column A so i can use column A to find the total range for pasting formula Down.

    Below is an example ) that could work, but it copies the formula from cell 2 -down, rather than from the first empty cell-down.
    Cells(5,1).Select
    Selection.End(xlDown).Select
    lastRow = ActiveCell.Row
    Range(Cells(2,3),Cells(lastRow,3)) = .....my formula

    Thanks for the help.

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

    Re: Macro to find the first blank cell in a column and add formula till lastused row

    Sub FormulaToRowLast()
    Dim lr As Long
    lr = Cells(Rows.Count, "CY").End(xlUp).Row
        Range("CY" & lr & ":CZ" & Cells(Rows.Count, "A").End(xlUp).Row).FillDown
    End Sub
    Check all references and change if/where required.

  3. #3
    Registered User
    Join Date
    07-05-2018
    Location
    canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Macro to find the first blank cell in a column and add formula till lastused row

    thank you for your reply. It worked like a charm.

    one more question, How would I change the range , if I have to fill down the formulas in column CP, CY and DD. thanks

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

    Re: Macro to find the first blank cell in a column and add formula till lastused row

    Try this.

    It assumes that Columns CP (94), CY (102) and DD (108) all have the same last row.
    It uses Column A as a benchmark for maximun rows.

    Sub FillDown_To_Last_Row()
    Dim lr1 As Long, lr2 As Long, colArr, i As Long
    
    lr1 = Cells(Rows.Count, 94).End(xlUp).Row
    lr2 = Cells(Rows.Count, 1).End(xlUp).Row
    colArr = Array(94, 103, 108)    '<---- numericals for Columns CP, CY and DD
    
    Application.ScreenUpdating = False
        For i = LBound(colArr) To UBound(colArr)
            Range(Cells(lr1, colArr(i)), Cells(lr2, colArr(i))).FillDown
        Next i
    Application.ScreenUpdating = True
    End Sub

  5. #5
    Registered User
    Join Date
    07-05-2018
    Location
    canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Macro to find the first blank cell in a column and add formula till lastused row

    Thank You!

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

    Re: Macro to find the first blank cell in a column and add formula till lastused row

    The code in Post #4 is easy to expand if needed and so is this one.
    Just a slightly different way of attacking the problem.
    Have fun.
    Sub FillDown_To_Last_Row_2()
    Dim lr1 As Long, lr2 As Long
    lr1 = Cells(Rows.Count, 94).End(xlUp).Row
    lr2 = Cells(Rows.Count, 1).End(xlUp).Row
    
    Application.ScreenUpdating = False
        Application.Union(Range(Cells(lr1, 94), Cells(lr2, 94)), Range(Cells(lr1, 103), Cells(lr2, 103)), Range(Cells(lr1, 108), Cells(lr2, 105))).FillDown
    Application.ScreenUpdating = True
    
    End Sub
    Good luck and thanks for letting us know that it all worked to your needs.

+ 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. How to find difference of two columns till blank space in column B
    By aleanboy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2014, 04:11 PM
  2. Counting text in between Months in a column till next blank cell
    By sapell in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-13-2014, 04:41 PM
  3. [SOLVED] I need a macro to copy down till adjacent column ends in a blank cell
    By Paul Hayward in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2014, 02:27 PM
  4. [SOLVED] Formula for a cell value to show as blank till the varible has been entered
    By arkadd61 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-27-2013, 09:46 PM
  5. Find a blank cell and calculate the average of all cells above till the next blank
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 11:51 AM
  6. Select a specific column till it identifies blank cell and to format
    By k1234y in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2012, 12:35 AM
  7. [SOLVED] Is it possible to create a macro that repeats for the cell below till reaching a blank cel
    By CDNcameron in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-05-2012, 06:07 PM

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