I am trying to copy and paste data from one Workbook's sheet to another (2 different workbooks). However, only to paste data into the unprotected cells on the destination worksheet. Both worksheets have an identical structure. It would be awesome to get your help to debug this and here is what I've put together so far:
Sub PasteData()
Dim sourceWB As Workbook, targetWB As Workbook, sourceRange As Range, targetRange As Range, scell As Range, tcell As Range
Set sourceWB = Workbooks.Open("Target.xlsx")
Set sourceRange = sourceWB.Sheets("Tsheet").Range("D2:BE109")
Set targetWB = Workbooks.Open("Source.xlsx")
Set targetRange = targetWB.Sheets("Source").Range("D2:BE109")
For Each tcell In targetRange
For Each scell in Range sourceRange
If Not tcell.Locked Then
If Not scell Is Nothing Then
Set tcell = scell
End If
End If
Next scell
Next tcell
End Sub
tcell.Value = scell.Value
, noSet
– Tim Williams