I was hoping someone might be able to help me out with this. I have included the code that I am currently working with. This allows me to transfer a range of data from ws1(Current Performance) to ws2(Past Monthly Performance) and it appends to the next blank row; however, I would like for it to overwrite the existing data based on a condition otherwise it should append it to the next blank row.
For example, C3 on ws1 shows May 2017. If ws2 has a section that shows May 2017, then I need that range overwritten; otherwise, the new data should append to the existing data.
Any assistance would be greatly appreciated.
Sub CopyAllData()
'update these Const values for Worksheet 1
Const ws1Name = "Current Performance"
Const firstRowToCopy = 3
Const alwaysUsedCol = "C"
Const firstColToCopy = "C"
Const lastColToCopy = "I"
Const ws2Name = "Past Monthly Performance"
'end of user definable Const values
Dim ws1 As Worksheet
Dim ws1LastRow As Long
Dim ws1CopyRange As Range
Dim ws2 As Worksheet
Dim ws2NextRow As Long
Set ws1 = Worksheets(ws1Name)
Set ws2 = Worksheets(ws2Name)
ws1LastRow = ws1.Range(alwaysUsedCol & Rows.Count).End(xlUp).Row
If ws1LastRow < firstRowToCopy Then
ws1LastRow = firstRowToCopy
End If
Set ws1CopyRange = ws1.Range(firstColToCopy & firstRowToCopy & _
":" & lastColToCopy & ws1LastRow)
ws2NextRow = ws2.Range(alwaysUsedCol & Rows.Count).End(xlUp).Row + 2
ws1CopyRange.Copy
'copy all
ws2.Range(firstColToCopy & ws2NextRow).PasteSpecial Paste:=xlAll
Application.CutCopyMode = False
'all done
Set ws1CopyRange = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
End Sub
Bookmarks