W
Will
Can someone help with code to delete multiple columns from an excel
spreadsheet? I know which columns I need to delete. The code below will
delete a single column but I'm not sure how to delete multiple columns. I'm
tried experimenting with Dim rg As Excel.Range = xlSheet.Columns("B, D, G,
K, L") but no joy. Thanks in advance
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Open("D:\August_Sales.xls")
xlSheet = xlBook.Worksheets(1)
Dim rg As Excel.Range = xlSheet.Columns("B")
rg.Select()
rg.Delete()
xlBook.Save()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing
spreadsheet? I know which columns I need to delete. The code below will
delete a single column but I'm not sure how to delete multiple columns. I'm
tried experimenting with Dim rg As Excel.Range = xlSheet.Columns("B, D, G,
K, L") but no joy. Thanks in advance
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Open("D:\August_Sales.xls")
xlSheet = xlBook.Worksheets(1)
Dim rg As Excel.Range = xlSheet.Columns("B")
rg.Select()
rg.Delete()
xlBook.Save()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing