Dear Friends,
I have below code to copy the data and paste in concerned sheet, sheet name is mentioned Sheet98.Range("C12:C137"). this is perfectly working, currently it is pasting in the second row of concerned sheet, I wanted paste data 25th row of concerned sheet, I am trying to change the below part of the code, not succeeded, could you please help me on this.
r1.Copy sh1.Cells(sh1.Rows.Count, "D").End(xlUp).Offset(1, 0)
I have below code to copy the data and paste in concerned sheet, sheet name is mentioned Sheet98.Range("C12:C137"). this is perfectly working, currently it is pasting in the second row of concerned sheet, I wanted paste data 25th row of concerned sheet, I am trying to change the below part of the code, not succeeded, could you please help me on this.
r1.Copy sh1.Cells(sh1.Rows.Count, "D").End(xlUp).Offset(1, 0)
Code:
Sub copytosheet()
Dim lstrw As Integer
Dim sh As Worksheet, sh1 As Worksheet
Dim r As Range, cell As Range, r1 As Range
Set sh = Sheet98
Set r = Sheet98.Range("C12:C137")
For Each cell In r
If Len(Trim(cell.Value)) > 0 Then
Set sh1 = Nothing
On Error Resume Next
Set sh1 = Worksheets(cell.Text)
On Error GoTo 0
If Not sh1 Is Nothing Then
Set r1 = sh.Range(sh.Cells(cell.Row, "E"), sh.Cells(cell.Row, "G"))
r1.Copy sh1.Cells(sh1.Rows.Count, "D").End(xlUp).Offset(1, 0)
End If
End If
Next
End Sub