Search : in
By :

Copy column data matching the column name

Last answer on Feb 5, 2009 12:42:37 am GMT spaceenigma, on Jan 28, 2009 3:32:32 am GMT 
 Report this message to moderators

Hello,

In Excel 2003/XP/2000/97, how do I write a macro that will look for selected column headers . If found, it will copy that entire column to a new sheet in that same file?

For example, if my column headers look like this,

"Product ID" "Product Name" "Unit Price" "Units In Stock" "Description"

I need to pull all the rows under ProductID, UnitPrice, 'Units in stock" into a new sheet and group the identical products with Total of "units in stock"

Thanks,

Configuration: Windows Vista
Internet Explorer 7.0

Best answers for « Copy column data matching the column name » in :
[Excel] Sorting rows only Show[Excel] Sorting rows only Microsoft Excel by default perform a sort on the columns (Data/Sort). To sort the data horizontally, just select the data to be sorted, then Data tab /Sort/ Options/ check the Sort Left to right box in the...
Excel – Comparing cell A1 to entire A column in Sheet 2 ShowExcel – Comparing cell A1 to entire A column in Sheet 2 Issue Solution Note Issue I have been trying to compare sheet1 A2 to sheet2 A2 through A500 and if it exists somewhere in sheet2's a col then copy that entire row to a new sheet....
Transforming columns into lines ShowTransforming columns into lines Example Limitations It is endemic for most Linux tools to work with lines, but not with columns (sed, awk, grep, etc..). However, it may happens,that you have a file where the data should be read in...
Download BurnAtOnce ShowBurn At Once is a software of free engraving, possessing a minimalist interface but interesting features: · Creation of CD audio from WAV, MP3 or OGG file, · Copy of data or audio CD, · Creation of ISO images from a CD, · Burning of ISO...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...

1

 Helper, on Feb 5, 2009 12:42:37 am GMT
  • +2

I am assuming the sheet you want to transfer to has the three heading names in the order you stated.
Hope this helps.


Private Sub TransferRows()

Set s = Sheets("Sheet1")
Set t = Sheets("Sheet2")
Dim i
Dim b
i = 2
b = 1


Do Until IsEmpty(s.Range("A" & i))

If s.Range("A1") = t.Range("A1") And s.Range("C1") = t.Range("B1") And s.Range("D1") = t.Range("C1") Then
b = b + 1
t.Range("A" & b) = s.Range("A" & i)
t.Range("B" & b) = s.Range("C" & i)
t.Range("C" & b) = s.Range("D" & i)
End If

i = i + 1

Loop

t.Range("A1").Sort _
Key1:=t.Columns("A"), _
Header:=xlGuess


End Sub

Reply to Helper