If cell contains text, copy above cell and paste loop

dinokovac93

New Member
Joined
Oct 10, 2017
Messages
11
Hi guys, I'm having trouble running a VBA. Seems fairly simple but not too sure how to do this. What I'm doing is going through every cell within a column. If a cell contains "N/A", then the vba will copy the cell above and paste it into that specific "N/A" cell. The VBA should loop until there are no more cells to go through.



Sub copyPasteTest()
Dim i As Long


For i = 4 To 4000
If Cells(i, 1).Value = "#N/A" Then
Cells(i, 1).Value = Cells(i, 1).Offset(-1, 0)
End If

Next i


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this:

Code:
Sub copyPasteTest()
Dim i As Long
Dim LR As Long

LR = Cells(Rows.Count, 1).End(xlUp).Row

For i = 4 To LR 'or if you prefer 4000, that works too...just an idea
    If IsError(Cells(i, 1).Value) = True Then
        Cells(i, 1).Value = Cells(i, 1).Offset(-1, 0)
    End If
Next i


End Sub
 
Upvote 0
Thank you, this is perfect.

Try this:

Code:
Sub copyPasteTest()
Dim i As Long
Dim LR As Long

LR = Cells(Rows.Count, 1).End(xlUp).Row

For i = 4 To LR 'or if you prefer 4000, that works too...just an idea
    If IsError(Cells(i, 1).Value) = True Then
        Cells(i, 1).Value = Cells(i, 1).Offset(-1, 0)
    End If
Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

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