Search : in
By :

Copy entire column if column title matches

Last answer on Sep 25, 2009 3:08:26 am BST Bethany2727, on Sep 24, 2009 3:24:35 pm BST 
 Report this message to moderators

Hi,

After several attemps at writing a Macro I need help! I am working in Excel 2007.

I have several Columns some of which are labeled "keep" and some are labelled "delete"
Is there a Macro that could delete all the data in Columns where the Column title is "delete" and keep the rest of the data?

Alternatively the macro could copy only the columns that are labelled "keep" onto a new sheet in the same workbook.

Any help writing a Macro would be great.

Thank you

Configuration: Windows XP Internet Explorer 7.0
Excel 2007.

Best answers for « Copy entire column if column title matches » in :
Copy an entire partition on Vista ShowCopy an entire partition on Vista Issue Solution Issue It is possible to copy the entire partition on your hard drive with the DVD of vista. It is very useful if you want to change your hard drive in order to restore all data....
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....
Copy rows based on a condition ShowCopy rows based on a condition Issue Solution Note Issue How can I have excel copy the entire row of data from worksheet Employee Inventory to another worksheet called EEs if column Q contains TERM. I've tried almost everything but...
Download Shadow Copy ShowNormally, the administrators of files as the explorer Windows do not allow the copy of opened or blocked files. For instance if you are treating a document Word, you have no possibility of copying it in another file during its edition. Shadow Copy is...
Using FTP commands ShowThe FTP protocol FTP (File Transfer Protocol) is a protocol — meaning a standard language that lets two machines communicate — used so that computers of different types (or with different operating systems) can transfer files over a...
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

 venkat1926, on Sep 25, 2009 3:08:26 am BST

Suppose that column headings (labels) are in row no 1 frrm A1 to right
in that case try ths macro (modify if necessary)
confirm if macro does what you want.

Sub test()
Dim del() As Range, rng As Range, j As Integer, k As Integer
Dim add As String
On Error Resume Next
Worksheets("sheet1").Activate
Set rng = Range(Range("A1"), Range("A1").End(xlToRight))

j = WorksheetFunction.CountIf(rng, "delete")
ReDim del(1 To j)
k = 1
Set del(k) = rng.Cells.Find(what:="delete", lookat:=xlWhole)
If del(k) Is Nothing Then Exit Sub
add = del(1).Address
MsgBox del(k).Address
k = k + 1
Do
Set del(k) = rng.Cells.FindNext(after:=del(k - 1))
If del(k) Is Nothing Then GoTo line1
If del(k).Address = add Then GoTo line1
MsgBox del(k).Address
k = k + 1
Loop
line1:
k = 0
For k = j To 1 Step -1
del(k).EntireColumn.Delete
Next k

End Sub


mine is exscel 2002 version

Reply to venkat1926