The following macro breaks at the line "cell.PasteSpecial Paste:=xlPasteAll". Why?
VBA Code:
Sub PasteCopiedCell()
'Declare variables
Dim cell As range
Dim range As range
Dim targetCell As range
'Prompt user to select a cell
Set cell = Application.InputBox("Select a cell to copy:", "Copy Cell", Type:=8)
'Copy the cell
cell.Copy
'Prompt user to select a range
Set range = Application.InputBox("Select a range to paste the cell into:", "Paste Range", Type:=8)
'Prompt user to select a cell
Set targetCell = Application.InputBox("Select a cell to paste the cell into:", "Paste Cell", Type:=8)
'Loop through the range
For Each cell In range
'If the cell on the same row in the targetCell column is not empty, then paste the copied cell
If cell.Offset(0, targetCell.Column - cell.Column).Value <> "" Then
cell.PasteSpecial Paste:=xlPasteAll
End If
Next cell
End Sub