0
votes

I am selecting two cell ranges and trying to copy the first cell range to the second cell range after storing each selected range. when I use F8 to go step by step through the code it all works but when the last if statement is true, I cannot get the FirstCell to copy to the SecondCell

Sub Move()

Dim FirstCell As String
Dim SecondCell As String
Dim cel As Excel.Range
Dim count As Integer


Application.EnableEvents = False
count = 0
For Each cell In Selection

If count = 0 Then
FirstCell = cell.Value
FirstCell1 = cell.Address

End If

If count = 1 Then
SecondCell = cell.Value
SecondCell1 = cell.Address

End If

count = count + 1

Next


If FirstCell <> "" And SecondCell = "" And count = 2 Then 'Else Exit Sub

Selection.FirstCell.Copy
SecondCell1.PasteSpecial


End If

End Sub
1

1 Answers

0
votes

Seems rather convoluted. To paste you need

Range(FirstCell1).Copy Range(SecondCell1)

FirstCell1 and SecondCell1 are addresses. i.e. strings, and hence cannot be copied, which is a method of the Range object.

You should get in the habit of declaring all your variables and using Option Explicit.