ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel 2003 (https://www.excelbanter.com/excel-discussion-misc-queries/137094-excel-2003-a.html)

Kim Kautzmann

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

Gary''s Student

Excel 2003
 
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
--
Gary's Student
gsnu200712


"Kim Kautzmann" wrote:

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?


Kim Kautzmann[_2_]

Excel 2003
 
Thanks so much. This works perfectly.

"Gary''s Student" wrote:

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
--
Gary's Student
gsnu200712


"Kim Kautzmann" wrote:

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?



All times are GMT +1. The time now is 09:57 PM.

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