Results 1 to 6 of 6

Error when selecting last row

Threaded View

  1. #1
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Thumbs down Error when selecting last row

    Hey there,

    I am trying to delete all the data on "Sheet1" of my spreadsheet except row 1 but using the code below, I keep getting an error when the macro is trying to calculate the end row and column, can any tell me where I am going wrong...and to stop me from going bonkers?!

    Sub clear_sheet_content()
    
    Dim oSheet As Excel.Worksheet
    Dim col As Integer
    Dim row As Integer
    
    Set oSheet = Worksheets("Sheet1")
    
    col = ActiveSheet.UsedRange.Columns.count
    row = ActiveSheet.UsedRange.Rows.count + ActiveSheet.UsedRange.row - 1
    
        On Error GoTo Errhandler
        
        oSheet.Range(cells(2, 1), cells(row, col)).Select
        Selection.ClearContents
        Selection.NumberFormat = "General"
        MsgBox "The sheet has been cleared", vbInformation, "Add Non Conformity"
        
    Errhandler:
    
        MsgBox "There is no data on sheet1", vbInformation, "Add Non Conformity"
        
        
    End Sub
    Cheers,

    Jag
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1