Delete Columns

  • Thread starter Thread starter Jean
  • Start date Start date
J

Jean

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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top