Excel 2003

G

Guest

I have a spreadhseet whose columns change each month. I want to automatically
delete all the columns in the spreadsheet ecept for the first and last
columns. Is there a way to do this automatically?
 
G

Guest

Sub columnator()

Set r = ActiveSheet.UsedRange
nLastColumn = r.Columns.Count + r.Column - 1
nFirstcolumn = r.Column

For i = nLastColumn - 1 To nFirstcolumn + 1 Step -1
Columns(i).EntireColumn.Delete
Next

End Sub
 
G

Guest

Thanks so much. This works perfectly.

Gary''s Student said:
Sub columnator()

Set r = ActiveSheet.UsedRange
nLastColumn = r.Columns.Count + r.Column - 1
nFirstcolumn = r.Column

For i = nLastColumn - 1 To nFirstcolumn + 1 Step -1
Columns(i).EntireColumn.Delete
Next

End Sub
 

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

Top