Question : Macro to keep certain colums and delete the rest.

I have a header in row 1.  In this row I need to find two column headings of Account Number and Check Amount.  I need to keep the data in these two columns, and delete the remaining columns.  How can I write a macro to perform this?  Thank you.

Troy

Answer : Macro to keep certain colums and delete the rest.

Try the attached code.

Thomas
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Sub Macro3()
Dim col1, col2, colTemp

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

col1 = Rows(1).Find(What:="Check Amount", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Column
col2 = Rows(1).Find(What:="Account Number", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Column

If col1 < col2 Then
    colTemp = col1
    col1 = col2
    col2 = colTemp
End If

Range(Cells(1, col1 + 1), Cells(1, Columns.Count)).EntireColumn.Delete
If col1 > col2 + 1 Then Range(Cells(1, col2 + 1), Cells(1, col1 - 1)).EntireColumn.Delete
Range(Cells(1, 1), Cells(1, col2 - 1)).EntireColumn.Delete

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Random Solutions  
 
programming4us programming4us