+ Reply to Thread
Results 1 to 6 of 6

Help edit this code so that it loops through specific worksheets

Hybrid View

rocksan Help edit this code so that... 07-18-2012, 01:25 AM
Trebor76 Re: Help edit this code so... 07-18-2012, 01:37 AM
rocksan Re: Help edit this code so... 07-18-2012, 01:54 AM
Trebor76 Re: Help edit this code so... 07-18-2012, 02:03 AM
rocksan Re: Help edit this code so... 07-18-2012, 03:21 AM
Trebor76 Re: Help edit this code so... 07-18-2012, 05:35 AM
  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Help edit this code so that it loops through specific worksheets

    Hi everyone, can anyone help edit this code so that it loops through specific named worksheets "A", "B", "C","D" in my workbook.

    Thanks.


    Sub ClearERRvalues()
    Dim rng As Range
    Dim cell As Range
    Set rng = Range("A1:z1000")
    For Each cell In rng
    If cell.Text = "#DIV/0!" Then
    cell.ClearContents
    ElseIf cell.Text = "#N/A" Then
    cell.ClearContents
    End If
    Next cell
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Help edit this code so that it loops through specific worksheets

    Hi rocksan,

    Are the error messages the result of existing formulas or have they been converted to values so it's just the text that's showing?

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Help edit this code so that it loops through specific worksheets

    Hi Robert,

    Quote Originally Posted by Trebor76 View Post
    Hi rocksan,

    Are the error messages the result of existing formulas or have they been converted to values so it's just the text that's showing?

    Robert
    The formulas are used to do some calculation, sometimes the calculation divides by zero, thats why it results in the error. The N/A happens when the data itself is unavailable yet for calculation. Another sheets uses the calculated data, since the data is either #DIV/0 or #N/A, the whole formula fails. The macro is just a quick fix i need to clear those errors on corresponding sheets, I just want it to loop automatically, instead of finding and fixing the affected sheet manually.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Help edit this code so that it loops through specific worksheets

    OK so I'll assume the errors are the result of existing formula's, try this (initally on a copy of the workbook in case the results are not as expected):

    Option Explicit
    Sub Macro3()
    
        'http://www.excelforum.com/excel-programming/846061-help-edit-this-code-so-that-it-loops-through-specific-worksheets.html
    
        Dim varMySheet As Variant
        
        For Each varMySheet In Array("A", "B", "C", "D")
            With Sheets(varMySheet).Range("A1:Z1000")
                On Error Resume Next 'OK to ignore 'no cells found error message'
                    .SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents 'Clear existing formula generated errors
                On Error GoTo 0
            End With
        Next varMySheet
        
    End Sub
    HTH

    Robert

  5. #5
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Help edit this code so that it loops through specific worksheets

    The code works perfectly.

    You're so helpful. Thank you very much Robert.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Help edit this code so that it loops through specific worksheets

    Thanks for the feedback and I'm glad we were able to solve the issue

+ Reply to Thread

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