Forum Discussion

mary_anderson's avatar
mary_anderson
New Contributor
11 years ago

Excel Ranges - Using Column Numbers rather than letters

Hi all,



As part of one of my routines, I'd like to "Clear Contents" of a range in Excel, using the COM object.  However, I'd like to use numbers to represent the columns rather than letters.  Is that possible?  The method below didn't work, which I tried from using an example from StackExchange.

http://stackoverflow.com/questions/13157363/create-excel-ranges-using-column-numbers-in-vba





Sub clearRange

set xl = Sys.OleObject("Excel.Application")

xl.Visible = TRUE

Set workbook = xl.ActiveWorkbook

Set range1 = workbook.ActiveSheet.Range(.Cells(11, 8), .Cells(15, 12))

range1.clearContents

End Sub



Thanks,

M
  • Try this:




    Sub clearRange


    set xl = Sys.OleObject("Excel.Application")


    xl.Visible = TRUE


    Set workbook = xl.ActiveWorkbook


    Set worksheet = workbook.ActiveSheet


    Set range1 = worksheet.Range(worksheet.Cells(11, 8), worksheet.Cells(15, 12))


    range1.clearContents


    End Sub

  • Try this:




    Sub clearRange


    set xl = Sys.OleObject("Excel.Application")


    xl.Visible = TRUE


    Set workbook = xl.ActiveWorkbook


    Set worksheet = workbook.ActiveSheet


    Set range1 = worksheet.Range(worksheet.Cells(11, 8), worksheet.Cells(15, 12))


    range1.clearContents


    End Sub