+ Reply to Thread
Results 1 to 3 of 3

Fill blank cells in column with value above

Hybrid View

  1. #1
    Registered User
    Join Date
    06-27-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    55

    Question Fill blank cells in column with value above

    Dear Expert,
    I was learnt to to autofill of the cells with value above.
    But when I found the Fonts changed, it did not work.
    Can you tell me how to fine-tune and make it work all the time either for text or numbers?
    Thanks
    Elton


    Sub FillColBlanks()
    'fill blank cells in column with value above
    Dim wks As Worksheet
    Dim rng As Range
    Dim LastRow As Long
    Dim col As Long
    
    Set wks = ActiveSheet
    With wks
       col = ActiveCell.Column
       'or
       'col = .range("b1").column
    
       Set rng = .UsedRange  'try to reset the lastcell
       LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
       Set rng = Nothing
       On Error Resume Next
       Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
       On Error GoTo 0
    
       If rng Is Nothing Then
          
           Exit Sub
       Else
           rng.FormulaR1C1 = "=R[-1]C"
       End If
    
       'replace formulas with values
       With .Cells(1, col).EntireColumn
           .Value = .Value
       End With
    
    End With
    
    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Fill blank cells in column with value above

    Changing the Font should not affect the code, not should being a number or text
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Fill blank cells in column with value above

    Do you want to copy the fonts and format or not?

    Sub FillColBlanks_Copy_Values_Only()
    
        On Error Resume Next
        With ActiveCell.EntireColumn.SpecialCells(xlCellTypeBlanks)
            .FormulaR1C1 = "=R[-1]C"
            .Value = .Value
        End With
    
    End Sub
    
    Sub FillColBlanks_Copy_ValuesAndFormatting()
    
        Dim a As Range
        Application.ScreenUpdating = False
        On Error Resume Next
        With ActiveCell.EntireColumn.SpecialCells(xlCellTypeBlanks)
            For Each a In .Areas
                a.Offset(-1).Resize(1).Copy
                a.PasteSpecial xlPasteFormats
                a.PasteSpecial xlPasteValues
            Next a
        End With
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    
    End Sub

+ 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