From: Vikram on
Hello All,
am newbie to excel, i have a workbook which has multiple worksheets and all
these worksheets contains many unwanted columns. i would like to develop a
macro which will keep only the columns that i need in all the worksheet.
Please help me in this regard
From: JLGWhiz on
What criteria determines if the column is not wanted?


"Vikram" <Vikram(a)discussions.microsoft.com> wrote in message
news:FA2E6FA2-3146-4CC9-BA72-E55D19CAB820(a)microsoft.com...
> Hello All,
> am newbie to excel, i have a workbook which has multiple worksheets and
> all
> these worksheets contains many unwanted columns. i would like to develop a
> macro which will keep only the columns that i need in all the worksheet.
> Please help me in this regard


From: Paul Robinson on
Hi
not very elegant but

Sub removecolumns()
Dim ws As Worksheet
Dim columnarray As Variant
Dim arraysize As Integer, i As Integer

Application.ScreenUpdating = False
columnarray = Array(1, 3, 7, 8, 9)
arraysize = UBound(columnarray)

For Each ws In ActiveWorkbook.Worksheets
For i = arraysize To 0 Step -1
ws.Columns(columnarray(i)).Delete
Next i
Next ws
End Sub

Replace your array values with the columns you need to remove.
note: Array is 0 based so counting starts at 0. You run the delete
from right to left or you will delete coulmns you need to keep as
deletion will upset the column number.
regards
Paul

On Apr 22, 6:44 pm, Vikram <Vik...(a)discussions.microsoft.com> wrote:
> Hello All,
> am newbie to excel, i have a workbook which has multiple worksheets and all
> these worksheets contains many unwanted columns. i would like to develop a
> macro which will keep only the columns that i need in all the worksheet.
> Please help me in this regard