Extract specific fields and its values from multiple sheets to one summary sheet

vbanewuser

New Member
Joined
Apr 20, 2018
Messages
3
I'm trying to extract specific fields from multiple sheets in to one sheet. Each sheet has multiple rows with row heading as ID, name, total costs, total revenue. I need to find the rows that have these headings. Then the value for each one is listed in different columns - like ID value is listed in Column C, name in column C again, total costs in column G and total revenue in column J. Macro I've just copies and pastes all rows with these values. but I was looking for values to updated in columns set as ID, name, total costs, total revenue in summary sheet and pasting all values from multiple sheets to this sheet under these column headers.

Here is the sample of data in multiple sheets with total costs and total revenue in different row counts. Columns for values in each field is constant, so column B in below table will be used to extract ID and name details, Column to extract total costs and column I to extract total revenue value.


ID123
Name
abcd
cost 1
123
cost 2
3456
Total Costs
100000
Cost adjustment

12
Total revenue
300000

<tbody>
</tbody>


Here is what I am looking for in summary sheet:

ID
Name
Total Costs
Total Revenue
123
abcd
100000
300000
456 (from next sheet)
efgh (from next sheet)
150000 (from next sheet)
400000 (from next sheet)

<tbody>
</tbody>

Please help.

Thank you.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Maybe try this on a copy of your workbook.
Copies from all sheets except first (leftmost) sheet.
First (leftmost) sheet is called "summary".
Copied values will be pasted in first (leftmost) sheet.
Check all your spelling. Different spelling will error code. Change where required.

Code:
Sub Transfer_From_All_Sheets()
Dim i As Long, a
Sheets("summary").Range("A1:D1").Value = Array("ID", "Name", "Total Costs", "Total Revenue")
    For i = 2 To ActiveWorkbook.Sheets.Count
        a = Array( _
        Sheets(i).Range("A:A").Find("ID", , , 1).Offset(, 2).Value, _
        Sheets(i).Range("A:A").Find("Name", , , 1).Offset(, 2).Value, _
        Sheets(i).Range("A:A").Find("Total Costs", , , 1).Offset(, 6).Value, _
        Sheets(i).Range("A:A").Find("Total revenue", , , 1).Offset(, 9).Value)
        Sheets("summary").Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 4) = a
    Next i
End Sub
 
Upvote 0
Hi, I tried this code. It copies the column headers as ID, Name, Total costs, Total Revenue and then stops. Debug message shows "Object variable or With block variable not set". Would you know what it refers it? Thanks.


Maybe try this on a copy of your workbook.
Copies from all sheets except first (leftmost) sheet.
First (leftmost) sheet is called "summary".
Copied values will be pasted in first (leftmost) sheet.
Check all your spelling. Different spelling will error code. Change where required.

Code:
Sub Transfer_From_All_Sheets()
Dim i As Long, a
Sheets("summary").Range("A1:D1").Value = Array("ID", "Name", "Total Costs", "Total Revenue")
    For i = 2 To ActiveWorkbook.Sheets.Count
        a = Array( _
        Sheets(i).Range("A:A").Find("ID", , , 1).Offset(, 2).Value, _
        Sheets(i).Range("A:A").Find("Name", , , 1).Offset(, 2).Value, _
        Sheets(i).Range("A:A").Find("Total Costs", , , 1).Offset(, 6).Value, _
        Sheets(i).Range("A:A").Find("Total revenue", , , 1).Offset(, 9).Value)
        Sheets("summary").Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 4) = a
    Next i
End Sub
 
Upvote 0
Do all the sheets, except the first sheet, have "ID", "Name", "Total Costs" and "Total revenue" in the first column (Column A)?
Is the spelling the same? Capitals or non capitals, leading or trailing spaces etc etc
In your post you mention "multiple sheets". Does that mean some sheets and not all?
If so, what are the restrictions? Which sheets are to be included or which sheets are to be excluded?
If all else fails, drop your workbook in "Dropbox" and give us the link to it.
 
Upvote 0
Yes, spelling same and capital, leading, trailing spaces are same.
I meant all sheets. Have created the "summary" as left most sheet.
All sheets have ID and Name in merged columns A through C and total costs/total revenue in merged columns A through D.
I tried changing range from "A:C" but did not work.
Do all the sheets, except the first sheet, have "ID", "Name", "Total Costs" and "Total revenue" in the first column (Column A)?
Is the spelling the same? Capitals or non capitals, leading or trailing spaces etc etc
In your post you mention "multiple sheets". Does that mean some sheets and not all?
If so, what are the restrictions? Which sheets are to be included or which sheets are to be excluded?
If all else fails, drop your workbook in "Dropbox" and give us the link to it.
 
Upvote 0
What happens when you un-merge the cells? Then check if all the info to be copied is in the right columns.
BTW, merging is considered a problem in the making. If not really necessary, don't use it. Use "Center Across Selection" instead
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,386
Members
448,891
Latest member
tpierce

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