Macro to Generate Customised Report

kaffal

Board Regular
Joined
Mar 7, 2009
Messages
68
Hi all, I wan to generate a customised report based on a Workbook(Data).
In the data workbook, there are up to 25 headers, could be more or less depend on the report recieved. The headers are found in row3.

However I wan to create a customised report to several parties.

- First When I run the macro, It will list out all the heading in a form, found in row 3, B2 onward. The number of headers may varies. In the form, I am able to select which headers I wan to include in the customsed report.

- After selecting the selected headers, It will copy the data found below the headers.

- It will copy to my customised report workbook.

Example: Those colored heading are those

Excel Workbook
BCDEFGHIJKLMNOP
3Header1Header2Header3Header4Header5Header6Header7Header8Header9Header10Header11Header12Header13Header14Header15
4Data 1Data 2Data 3Data 4Data 5Data 6Data 7Data 8Data 9CapturedData 11Data 12Data 13Data 14Data 15
5Data 2Data 4Data 5Data 6Data 7Data 8Data 9Data 10Data 11CapturedData 13Data 14Data 15Data 16Data 17
6
7Num1Num2Num3Num4Num5Num6Num7Num8Num9GeneratedNum11Num12Num13Num14Num15
8Info3Info4Info5Info6Info7Info8Num8Info10Info11GeneratedInfo13Info14Info15Num15Num16
9Info4Info5Num7Num8Num9Num10Num9Num12Num13GeneratedNum15Num16Num17Num16Num17
Data WorkBook
Customised Report
Excel Workbook
BCDEFGHIJK
3Header1Header2Header3Header4Header6Header7Header10Header11Header12Header15
4Data 1Data 2Data 3Data 4Data 6Data 7CapturedData 11Data 12Data 15
5Data 2Data 4Data 5Data 6Data 8Data 9CapturedData 13Data 14Data 17
6
7Num1Num2Num3Num4Num6Num7GeneratedNum11Num12Num15
8Info3Info4Info5Info6Info8Num8GeneratedInfo13Info14Num16
9Info4Info5Num7Num8Num10Num9GeneratedNum15Num16Num17
Report WorkBook
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If you colour the cells yellow this will copy just those columns to the "Report" sheet

SHEET NAME = "DATA"
SHEET NAME = "REPORT"

Code:
Sub generatereport()

Dim rng As Range

Set rng = Sheets("Data").Range("A1", Sheets("Data").Range("Z1").End(xlToLeft))

For Each Item In rng
    If Item.Interior.ColorIndex = 6 Then
        Item.EntireColumn.Copy Destination:=Sheets("Report").Range("Z1").End(xlToLeft).Offset(, 1)
    End If
    
Next Item
    

End Sub
 
Upvote 0
improvement

Code:
Sub generatereport()
Sheets("report").Cells.ClearContents
Dim rng As Range

Set rng = Sheets("Data").Range("A1", Sheets("Data").Range("Z1").End(xlToLeft))

For Each Item In rng
    If Item.Interior.ColorIndex = 6 Then
        Item.EntireColumn.Copy Destination:=Sheets("Report").Range("Z1").End(xlToLeft).Offset(, 1)
        Sheets("Report").Range("Z1").End(xlToLeft).Interior.ColorIndex = xlAutomatic
    End If
    
Next Item
    
Columns("A:A").Delete Shift:=xlToLeft
End Sub
 
Upvote 0
actually i highlight yellow is to show that I wan those headers to be copied.
How I select which headers to copied over is done on a form listing all the headers . if the checkbox beside the respective headers is ticked, it will be copied.
 
Upvote 0

Forum statistics

Threads
1,214,655
Messages
6,120,760
Members
448,991
Latest member
Hanakoro

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