PDA

View Full Version : [SOLVED] Copying Row Above Results In Zero Instead of Blank



nirvehex
01-05-2015, 03:26 PM
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-questions/827157-copying-row-above-results-zero-instead-blank.html

YasserKhalil
01-05-2015, 04:13 PM
Try changing this line

mrng.FormulaR1C1 = "=R[-1]C"
to this

mrng.FormulaR1C1 = "=IF(R[-1]C="""","""",R[-1]C)"

nirvehex
01-06-2015, 06:02 AM
Worked perfectly. Thank you, I appreciate it! :)

YasserKhalil
01-06-2015, 07:25 AM
You're welcome. thanks for the feedback