copy down info

muzzy

Active Member
Joined
Apr 8, 2014
Messages
333
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.

Code:
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
 
I have a formulas in column (C) to give me emp ID number from the emp name and ID in column (D) like (Adkins, Smith - 74826) The formulas gives me 74826 so I can match up with my roster. The formulas is this
Code:
=IFERROR(IF(D5="","",LOOKUP(10^5,MID(D5,MIN(FIND({1,2,3,4,5,6,7,8,9},D5&123456789)),{1,2,3,4,5})+0)),"")

That formulas goes all the way down column (C) and then I run the vb it gives me
Run Time error 1004
No cells were found

When I hit Debug it highlights (Range("B5:B" & lastRow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C")

But when I del the formulas from column (C) your VB work. What else can I do?? By the way thank you with your help on this and sorry if I am making it hard on you.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
It looks like in copying over the "blanks" that are being returned by your formula, Excel isn't recognizing those as blanks. This variation seems to work (I was hoping to avoid loops, but not big deal).
Code:
Sub MyCopy()


    Dim lastRow As Long
    Dim myRow As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column D with data
    lastRow = Cells(Rows.Count, "D").End(xlUp).Row
    
'   Copy data in column C to column B (assuming starting on row 5)
    For myRow = 5 To lastRow
        If Len(Cells(myRow, "C")) > 0 Then
            Cells(myRow, "B") = Cells(myRow, "C").Value
        Else
            Cells(myRow, "B") = Cells(myRow - 1, "B").Value
        End If
    Next myRow
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,172
Messages
6,129,291
Members
449,498
Latest member
Lee_ray

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top