Analyzing rows based on column headers and copying data from seperate columns

AaronCT

New Member
Joined
Apr 18, 2011
Messages
1
Hello all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I need help with a macro that analyzes the header of all columns and then it searches in each row if for certain data and if it meets the criteria it copies only the specified columns into a new sheet.<o:p></o:p>
Right now all I got is this macro that searches for the header and copies the whole column into a new sheet. <o:p></o:p>
Sub CopyColumns()<o:p></o:p>
Dim i, LastCol<o:p></o:p>
LastCol = Range("IV1").End(xlToLeft).Column<o:p></o:p>
For i = 1 To LastCol<o:p></o:p>
If UCase(Cells(1, i).Value) = "STATUS" Then<o:p></o:p>
Cells(1, i).EntireColumn.Copy Destination:= _<o:p></o:p>
Sheets("Sheet2").Range("A1")<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
If UCase(Cells(1, i).Value) = "COMPANY" Then<o:p></o:p>
Cells(1, i).EntireColumn.Copy Destination:= _<o:p></o:p>
Sheets("Sheet2").Range("B1")<o:p></o:p>
End If<o:p></o:p>
Next<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
Any help will be appreciated!<o:p></o:p>
Best regards.<o:p></o:p>
Aaron.<o:p></o:p>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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