Consulting

Results 1 to 4 of 4

Thread: Copying Row Above Results In Zero Instead of Blank

  1. #1

    Copying Row Above Results In Zero Instead of Blank

    Hello All -I have a code:


    Sub FillColBlanks()
    
    Dim wks As Worksheet
    Dim rng As Range
    Dim LastRow As Long
    Dim col As Long
    
    Set wks = ActiveSheet
    With wks
    
    
    
    
    
    
    
    
       
       col = .Range("Table28[[#Headers],[LC]]").Column
       col2 = .Range("Table28[[#Headers],[LCS]]").Column
       col3 = .Range("Table28[[#Headers],[SG]]").Column
       col4 = .Range("Table28[[#Headers],[V]]").Column
       col5 = .Range("Table28[[#Headers],[ABUN]]").Column
       col6 = .Range("Table28[[#Headers],[ML]]").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(4, col), .Cells(LastRow, col)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
       Set rng2 = .Range(.Cells(4, col2), .Cells(LastRow, col2 + 8)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
       Set rng3 = .Range(.Cells(4, col3), .Cells(LastRow, col3 + 3)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
       Set rng4 = .Range(.Cells(4, col4), .Cells(LastRow, col4 + 7)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
       Set rng5 = .Range(.Cells(4, col5), .Cells(LastRow, col5 + 1)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
       Set rng6 = .Range(.Cells(4, col6), .Cells(LastRow, col6 + 1)) _
                      .Cells.SpecialCells(xlCellTypeBlanks)
                      
       Set mrng = Union(rng, rng2, rng3, rng4, rng5, rng6)
    
    
    
    
       On Error GoTo 0
    
    
    
    
       If mrng Is Nothing Then
           MsgBox "No blanks found"
           Exit Sub
       Else
           mrng.FormulaR1C1 = "=R[-1]C"
       End If
       
     Range("B3").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
       
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
            xlNone, SkipBlanks:=False, Transpose:=False
    
    End With
    
    End Sub
    My question is, when it copies down the cell value above, if the cell above is blank it puts a 0 in the cell. How do I make it so it just leaves it blank? Thanks!

    This is cross posted at http://www.mrexcel.com/forum/excel-q...ead-blank.html

  2. #2
    Try changing this line
    mrng.FormulaR1C1 = "=R[-1]C"
    to this
    mrng.FormulaR1C1 = "=IF(R[-1]C="""","""",R[-1]C)"

  3. #3
    Worked perfectly. Thank you, I appreciate it!

  4. #4
    You're welcome. thanks for the feedback

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •