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


[TABLE="width: 500"]
<tbody>[TR]
[TD]DATA on Multiple SHEETS[/TD]
[TD]Column A[/TD]
[TD]Column B[/TD]
[TD]Column C[/TD]
[TD]Column D[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Row 5[/TD]
[TD]Formal Name[/TD]
[TD][/TD]
[TD]Miguel Smith[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Row 34[/TD]
[TD]Date[/TD]
[TD]Note[/TD]
[TD]Speaker[/TD]
[TD]Topic[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Row 35 through 52[/TD]
[TD]5/12/16[/TD]
[TD]xyz[/TD]
[TD]Y[/TD]
[TD]Politics[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]3/31/17[/TD]
[TD]abc[/TD]
[TD]n[/TD]
[TD]n/A[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="width: 500"]
<tbody>[TR]
[TD]Master 2[/TD]
[TD]Column A (Formal Name)[/TD]
[TD]Column B (Date)[/TD]
[TD]Column C (Note)[/TD]
[TD]Column D (Speaker)[/TD]
[TD]Column E (Topic)[/TD]
[/TR]
[TR]
[TD]Row 2[/TD]
[TD]Miguel Smith[/TD]
[TD]5/12/16[/TD]
[TD]xyz[/TD]
[TD]Y[/TD]
[TD]Politics[/TD]
[/TR]
[TR]
[TD]Row 3[/TD]
[TD]Miguel Smith[/TD]
[TD]3/31/17[/TD]
[TD]abc[/TD]
[TD]n[/TD]
[TD]n/a[/TD]
[/TR]
[TR]
[TD]Row4[/TD]
[TD]John Roberts[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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