Results 1 to 4 of 4

Method 'Range' of objects'_worksheet' failed

Threaded View

  1. #1
    Registered User
    Join Date
    12-08-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    37

    Method 'Range' of objects'_worksheet' failed

    Hi All

    Was wondering if anyone knows why I would be getting this error (Method 'Range' of objects'_worksheet' failed) when I try and run this code?
    The code works fine on the first sheet (Sheet1) but not on any of the remaining sheets (Sheet7 - Sheet 13)

    Dim ws As Worksheet
    Dim del2 As Long
    del2 = TextBox5.Value
    
    For Each ws In ActiveWorkbook.Worksheets
    If ws.CodeName = "Sheet1" Or ws.CodeName = "Sheet7" Or ws.CodeName = "Sheet8" Or ws.CodeName = "Sheet9" Or ws.CodeName = "Sheet10" Or ws.CodeName = "Sheet11" Or ws.CodeName = "Sheet12" Or ws.CodeName = "Sheet13" Then
    
    Select Case del2
    Case 1 To 13
    x = 16 - (13 - del2)
    
    'Commision Charge Static Test
    ws.Range(Cells(21, x), Cells(23, 15)).ClearContents                'Clear contents of unused cells first row of commision charge static test
    ws.Range("B24", "O41").Clear                                       'Clear unused rows from commision charge static test
    ws.Range("B23", "O23").Borders(xlEdgeBottom).LineStyle = xlDouble  'Adds boarder back to bottom of row 23
    
    'Capacity Static Test
    ws.Range(Cells(174, x), Cells(176, 15)).ClearContents                'Clear contents of unused cells first row of capacity static test
    ws.Range("B177", "O194").Clear                                       'Clear unused rows from capacity static test
    ws.Range("B176", "O176").Borders(xlEdgeBottom).LineStyle = xlDouble  'Adds boarder back to bottom of row 176
    
    'Pre Recharge Static Test
    ws.Range(Cells(338, x), Cells(340, 15)).ClearContents                'Clear contents of unused cells first row of pre recharge static test
    ws.Range("B341", "O358").Clear                                       'Clear unused rows from pre recharge static test
    ws.Range("B340", "O340").Borders(xlEdgeBottom).LineStyle = xlDouble  'Adds boarder back to bottom of row 340
    
    'Pre HDC Static Test
    ws.Range(Cells(499, x), Cells(501, 15)).ClearContents                'Clear contents of unused cells first row of pre HDC static test
    ws.Range("B502", "O519").Clear                                       'Clear unused rows from pre HDC static test
    ws.Range("B501", "O501").Borders(xlEdgeBottom).LineStyle = xlDouble  'Adds boarder back to bottom of row 501
    
    'After HDC Test
    ws.Range(Cells(548, x), Cells(550, 15)).ClearContents                'Clear contents of unused cells first row of after HDC static test
    ws.Range("B551", "O568").Clear                                       'Clear unused rows from after HDC static test
    ws.Range("B550", "O550").Borders(xlEdgeBottom).LineStyle = xlDouble  'Adds boarder back to bottom of row 550
    
    'Final Static Test
    ws.Range(Cells(597, x), Cells(599, 15)).ClearContents                'Clear contents of unused cells first row of final static test
    ws.Range("B600", "O617").Clear                                       'Clear unused rows from Final Static Test
    ws.Range("B599", "O599").Borders(xlEdgeBottom).LineStyle = xlDouble  'Adds boarder back to bottom of row 599
    
    
    End Select
    End If
    Next ws
    Last edited by grantastley; 01-29-2013 at 04:31 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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