ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deletes certain columns (https://www.excelbanter.com/excel-programming/369217-deletes-certain-columns.html)

T De Villiers[_92_]

Deletes certain columns
 

Hi, I have 25 columns.
I need to write a macro which goes through each column,
keeps:
1) Billing
2) GM
3) Total
4) Client
5) Project Name

but deletes the rest

I guess its something like this, many thks

sub del()

Dim i As Long
Dim aryTest

aryTest = Array("Billing ", "GM", "Total","Client","Project Name")

For i = 25 To 1 Step -1
If Not IsError(Application.Match(Cells(1, i).Value, aryTest, 0)) Then
'Keep
Else
'Delete
End If
Next i


End Su

--
T De Villier
-----------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...fo&userid=2647
View this thread: http://www.excelforum.com/showthread.php?threadid=56779


Jim Cone

Deletes certain columns
 
Sub del()
Dim i As Long
Dim aryTest As Variant

aryTest = Array("Billing ", "GM", "Total", "Client", "Project Name")

For i = 25 To 1 Step -1
If IsError(Application.Match(Cells(1, i).Value, aryTest, 0)) Then
Columns(i).Delete
End If
Next i
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"T De Villiers"
wrote in message
Hi, I have 25 columns.
I need to write a macro which goes through each column,
keeps:
1) Billing
2) GM
3) Total
4) Client
5) Project Name
but deletes the rest
I guess its something like this, many thks

sub del()

Dim i As Long
Dim aryTest

aryTest = Array("Billing ", "GM", "Total","Client","Project Name")

For i = 25 To 1 Step -1
If Not IsError(Application.Match(Cells(1, i).Value, aryTest, 0)) Then
'Keep
Else
'Delete
End If
Next i


End Sub
--
T De Villiers


T De Villiers[_93_]

Deletes certain columns
 

Thanks a lot Ji

--
T De Villier
-----------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...fo&userid=2647
View this thread: http://www.excelforum.com/showthread.php?threadid=56779



All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com