Im new to VBA so I am not that good. This a follow up question from my first question. VBA Copy and Paste Data with Matching Worksheet Name
I have a workbook containing worksheets "Summary" (where all data are consolidated, as shown in Fig.1), "8","9","10". I wanted to copy the data from "Summary" with the condition that if cell in Column A contains the worksheet name (8,9 or 10), that cell's row and Column C to E will pasted to the worksheet with matching name (shown in Fig.2). The data will be pasted in fixed Ranges C7 to E7, C14 to E14, C21 to E21 etc etc (7 increment). However, if the consecutive rows in Column B of "Summary" have equal values, they will be pasted beside each other (vague).For example, cells in Column A rows 2 to 6 in "Summary" contains "8", but column B rows 2 and 3 have similar values, thus Columns C to E rows 2 to 6 will be copied and pasted to sheet "8" at columns C7,C8, C14, C21 etc as shown in Fig 2. Link to my macro file: https://drive.google.com/file/d/18UalCvxIXuP6imVWZsWLRZPghMqogZp8/view?usp=sharing
I have the ff code from the previous thread maybe you can add or modify something:
Sub Copy_Data()
Dim lastRow As Long, offsetRow As Long, i As Long, No As String, NOSheet As Worksheet, auxRow As Long, summarySheet As Worksheet
Set summarySheet = Worksheets("Summary")
lastRow = summarySheet.Columns("A").Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
offsetRow = 7
For i = 2 To lastRow
No = Cells(i, "A")
Set NOSheet = Worksheets(No)
auxRow = NOSheet.Columns("C").Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
If auxRow > 1 Then auxRow = auxRow + 2
If auxRow = 1 Then auxRow = offsetRow
NOSheet.Cells(auxRow, "C") = summarySheet.Cells(i, "C")
NOSheet.Cells(auxRow, "D") = summarySheet.Cells(i, "D")
NOSheet.Cells(auxRow, "E") = summarySheet.Cells(i, "E")
Next i
End Sub
Thank you for your help!!!