Excel: copy down info

I have a vb that I got it work in other workbook and sheet. But I am trying to use it on a new worksheet and it will not work. Can some help me with it or give me a formulas that will do the same thing.

Sub copy()
Dim varData As Variant
Dim i As Long
varData = Sheet1.Range("C2:C4000") '// Read in the data.
For i = LBound(varData, 1) + 2 To UBound(varData, 1)
    If IsEmpty(varData(i, 1)) Then
        '// Cell is empty. Copy value from above.
        varData(i, 1) = varData(i - 1, 1)
    End If
Next i
'// Write result to sheet.
Sheet1.Range("B2").Resize(UBound(varData, 1) - LBound(varData, 1) + 1, 1) _
    = varData
End Sub

This question generated 23 answers. To proceed to the answers, click here.

This thread is current as of April 18, 2014.

For more resources for Microsoft Excel