VBA Copy certain rows from multiple sheets (not all) plus copy value of one cell

ExcelHelpNeeded99

New Member
Joined
Oct 6, 2017
Messages
13
Hi there,

Hoping someone can help.
I have a workbook with hundreds of sheets and I want to copy only for the ones with a "," in the sheet name. (These are the sheets with peoples names, one sheet per person)
All sheets are formatted the exact same way but the headers for row 2 through 33 are in column A with data in column C but on row 34 they switch to header being in row 34 with data in rows 35 through 52.

On the sheet called "Master2" I want to repeat the formal name in column A and show every event attended by that person on a separate row. Then it goes to the next sheet and does the same and so on.

Please can you help with the code?

Thanks


DATA on Multiple SHEETSColumn AColumn BColumn CColumn D
Row 5Formal NameMiguel Smith
Row 34DateNoteSpeakerTopic
Row 35 through 525/12/16xyzYPolitics
3/31/17abcnn/A

<tbody>
</tbody>


Master 2Column A (Formal Name)Column B (Date)Column C (Note)Column D (Speaker)Column E (Topic)
Row 2Miguel Smith5/12/16xyzYPolitics
Row 3Miguel Smith3/31/17abcnn/a
Row4John Roberts............

<tbody>
</tbody>
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I am not really sure that I understand your sheet layouts nor what you want copied, but you can try the code and post back with what needs to be fixed.

Code:
Sub t()
    For Each sh In ThisWorkbook.Sheets
        If sh.Name <> "Master2" And sh.Name Like "*,*" Then
            lr = sh.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
            Sheets("Master2").Cells(Rows.Count, 1).End(xlUp)(2) = sh.Range("C5").Value
            sh.Range("A35:D" & lr).Copy Sheets("Master2").Cells(Rows.Count, 1).End(xlUp).Offset(, 1)
        End If
    Next
End Sub
 
Upvote 0
Thanks JLGWhiz but I cant seem to get that to work.
On all sheets with a “,” I want the value from cell C5 (Persons name)
I then want the data from the rows A35 through D52 which is details of each event the person has attended.

I would like to format it in the master2 sheet so that there is one row per event and so each persons name will be repeated for 18 rows (I can always delete any blank event rows).

Persons name (Column A) Event details (Columns B,C,D,E)
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,787
Members
449,188
Latest member
Hoffk036

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top