Hi, I am using the below code which needs some modification.
When I click on the command button, it copies the data to another sheet paste it to the defined row.
But If there is old data that exists already it does nothing.
I want it to clear the previous data and paste the current data.
Here is the code:
Sub Update() Dim wsSource As Worksheet: Set wsSource = Sheets("Source") Dim lastrow As Long: lastrow = wsSource.Cells(Rows.Count, 1).End(xlUp).Row Dim wsDest As Worksheet: Set wsDest = Sheets("Dest") Dim rngRows As Range: Set rngRows = wsSource.Range("A2:A4") Dim rng As Range wsDest.Range("A1").Value = "" For Each rng In rngRows If rng = "" Then rng = rng ElseIf wsDest.Cells(rng.Value, 23) = "" Then wsDest.Cells(rng.Value, 23) = rng.Offset(, 2).Value ElseIf wsDest.Cells(rng.Value, 24) = "" Then wsDest.Cells(rng.Value, 24) = rng.Offset(, 2).Value ElseIf wsDest.Cells(rng.Value, 25) = "" Then wsDest.Cells(rng.Value, 25) = rng.Offset(, 2).Value End If Next rng End Sub
Hope someone helps me.
Thanks in advance.