+ Reply to Thread
Results 1 to 4 of 4

Auto Fill formulas for some columns

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Auto Fill formulas for some columns

    Hi There,

    Need help for resolving the below situation:

    Every time after a new batch extract I have to copy column to O from the new batch extact file at the last blank row and fill the formulas from A to H along with the new batch number.

    I have a macro which copy the new batch extract from new batch extract file at the firct blank row from column I through to last column. And it works perfectly fine.

    What I need is to update the macro to populate the formuals once I add any data for a new batch.

    I have attached a sample file to make things clearly understand what I am explaining. In
    the file 19th row to 24th row refers the new batch which I want to populate the formulas with for column A to H. I have copied the Column I to O fron the new batch extract say 6.

    Any ideas how can I say to fill these columns with formulas until last row upto which
    data is available.

    Any help and advice is very appreciated.

    My Code is below :
    Private Sub CommandButton1_Click()
    
    Dim ws As Worksheet
    Dim i As Long, j As Long, lrow As Long
    
    For j = 1 To 4
    
        With Sheets(j)
            If .FilterMode Then .ShowAllData
           .Cells.EntireRow.Hidden = False
           .Cells.EntireColumn.Hidden = False
        End With
    Next j    
    
    For i = 1 To 2
        Set ws = Workbooks("Batch_12_Report.xls").Worksheets(i)
        lrow = ws.Range("A" & Rows.Count).End(xlUp).Row
        ws.Range("A2:CZ2" & lrow).Copy ThisWorkbook.Worksheets(i).Range("K" & Rows.Count).End(xlUp).Offset(1, 0)
    Next i
    
    For i = 3 To 4
        Set ws = Workbooks("Batch_12_Report.xls").Worksheets(i)
        lrow = ws.Range("A" & Rows.Count).End(xlUp).Row
        ws.Range("A2:BG2" & lrow).Copy ThisWorkbook.Worksheets(i).Range("L" & Rows.Count).End(xlUp).Offset(1, 0)
    Next i
            
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Fill formulas for some columns

    Hi macrofan2012

    Perhaps something like this
    Sub Fill_Formula()
        Dim aLR As Long
        Dim lLR As Long
    
        With Sheet1
            aLR = .Range("A" & Rows.Count).End(xlUp).Row
            lLR = .Range("L" & Rows.Count).End(xlUp).Row
            .Range("A" & aLR & ":B" & aLR).AutoFill Destination:=.Range("A" & aLR & ":B" & lLR), Type:=xlFillDefault
            .Range("D" & aLR & ":G" & aLR).AutoFill Destination:=.Range("D" & aLR & ":G" & lLR), Type:=xlFillDefault
            .Calculate
        End With
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Auto Fill formulas for some columns

    Hi John,

    That works amazingly. Thank you very much. Much appreciate.

    Thanks,
    Su.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Fill formulas for some columns

    Hi Su

    You're welcome...glad I could help. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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