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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,967
Messages
6,175,673
Members
452,666
Latest member
AllexDee

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