+ Reply to Thread
Results 1 to 6 of 6

VBA to autofill columns

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    ATL
    MS-Off Ver
    2007
    Posts
    18

    VBA to autofill columns

    Good morning guys,

    I need help with a macro to autofill columns. In the attached sample, column A contains account numbers, column C:E contains other pertinent information that needs to be autofilled along the blank cells following the cell value. As an example, i need the contents of Cells A4, C4, D4, & E4 to copy all the way down to A15, C15, D15, & E15. The same process should repeat through the entire worksheet, which is over 200 pages long. Is this possible with a macro?

    Thanks,

    Doctor_H
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA to autofill columns

    This is the technique I use for this:
    Option Explicit
    
    Sub FillDownValues()
    Dim LR As Long, ws As Worksheet
    
    For Each ws In Worksheets
        LR = ws.Range("F" & ws.Rows.Count).End(xlUp).Row
        ws.Range("A1:E" & LR).SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
        With ws.Range("A1:E" & LR)
            .Value = .Value
        End With
        ws.Columns.AutoFit
    Next ws
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-22-2013
    Location
    ATL
    MS-Off Ver
    2007
    Posts
    18

    Re: VBA to autofill columns

    Thanks for the speedy response, Jerry! I tried the code provided and it appears to have worked but I got a run-time error '1004' "No Cells Were Found" after debigging it highlights the line in red below.

    Thanks again!

    Option Explicit
    
    Sub FillDownValues()
    Dim LR As Long, ws As Worksheet
    
    For Each ws In Worksheets
        LR = ws.Range("F" & ws.Rows.Count).End(xlUp).Row
        ws.Range("A1:E" & LR).SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
        With ws.Range("A1:E" & LR)
            .Value = .Value
        End With
        ws.Columns.AutoFit
    Next ws
    
    End Sub

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA to autofill columns

    Then your cells are actually empty. That code works on the sample file above. If you have another for me to look at I will do so. Is there a sheet in your workbook that should be skipped?

  5. #5
    Registered User
    Join Date
    02-22-2013
    Location
    ATL
    MS-Off Ver
    2007
    Posts
    18

    Re: VBA to autofill columns

    No worksheet that should be excluded in the workbook. The only thing I can think of that might be triggering the error are blank rows randomly placed throughout the worksheet. Could this be the issue?
    Last edited by Doctor_H; 02-26-2013 at 04:11 PM. Reason: Typographical error

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA to autofill columns

    Possibly, but that error implies there are NO blanks in the region, not random ones.

+ 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