ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Columns (https://www.excelbanter.com/excel-programming/293554-delete-columns.html)

Jean[_5_]

Delete Columns
 
I have spreadsheet and 5 columns get deleted before I
import into a database. At first I just did a record
macro and deleted assuming the formatted would not
change. What I want to do is look for a specific name and
then delete the entire column. So if the columns are
named MGMTCODE, CHANNEL, NAME1, CLASS, FUND NAME Delete.
The column names always start in the first row A1. There
are about 20 columns in all ans some months they change
the order on me.

Any suggestions on how I can do this?


Tom Ogilvy

Delete Columns
 
Dim varr as Variant, i as long, res as Variant
varr = Array("MGMTCODE", "CHANNEL", "NAME1", "CLASS", "FUND NAME")

for i = lbound(varr) to ubound(varr)
res = Application.Match(varr(i),Rows(1),0)
if not iserror(res) then
columns(res).EntireColumn.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Jean" wrote in message
...
I have spreadsheet and 5 columns get deleted before I
import into a database. At first I just did a record
macro and deleted assuming the formatted would not
change. What I want to do is look for a specific name and
then delete the entire column. So if the columns are
named MGMTCODE, CHANNEL, NAME1, CLASS, FUND NAME Delete.
The column names always start in the first row A1. There
are about 20 columns in all ans some months they change
the order on me.

Any suggestions on how I can do this?





All times are GMT +1. The time now is 03:38 PM.

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