0
votes

I am working on a VBA code to copy data from the second cell "A2" down to the last cell with data in it (this range will change). I then want to paste that data starting at the last row of column A on another sheet.

My VBA code as of now seems to do nothing. Can someone help me figure out why?

Option Explicit

Public Sub AddNotes()

Dim lastRow1 As String
Dim lastRow2 As String

lastRow1 = Sheets("PropertiesToMatch").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("PropertiesToMatch").Range("A2" & lastRow1).Copy

lastRow2 = Sheets("PropertyNotesToUpload").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("PropertyNotesToUpload").Range("A" & lastRow2).PasteSpecial Paste:=xlPasteValues

End Sub
2
And what is your question?cybernetic.nomad
@BigBen yeah I realized that and deleted that comment :)Zack E
You may want to change Dim lastRow1 As String and Dim lastRow2 As String to As Long?Zack E
@ZackE that is a good catch. I will incorporate into my answer.BigBen
Just one more observation. I believe it would be more prudent to qualify the sheets and ranges and instead of copying them make the ranges equal to each other from a performance standpoint. Granted without knowing how large the data set is it may not matter.Zack E

2 Answers

3
votes

Change

.Range("A2" & lastRow1)

to

.Range("A2:A" & lastRow1)

The first is only one cell, the second is the range you want.

Also, change

Dim lastRow1 As String
Dim lastRow2 As String

to

Dim lastRow1 As Long
Dim lastRow2 As Long

because Range.Row is a Long, not a String.

-2
votes
Option Explicit

Sub CopyPaste()
Dim i, j As Integer
Dim LastRow As Integer

With Sheets("PropertiesToMatch")
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
j = 2

For i = LastRow To 2 Step -1
Sheets("PropertiesToMatch").Cells(i, 1).Copy
Sheets("PropertyNotesToUpload").Cells(j, 1).PasteSpecial Paste:=xlPasteValues

j = j + 1
Next i

End Sub