Consulting

Results 1 to 3 of 3

Thread: Else If - Do Nothing

  1. #1
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location

    Else If - Do Nothing


    Morning all.

    I have the below code which finds an error code in a pivot sheet, then shows data, and renames that tab inline with the code.

    However ... these codes change daily.

    Im trying to understand where I would put else if, in order to skip if this code is not found and move onto the next code...

    Or a smarter way of writing the below example code.


    Sheets("Chris Error Code List").Select
        
        
        
        Cells.Find(What:="009", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
       
        ActiveCell.Offset(columnOffset:=1).Activate    Selection.ShowDetail = True
             Sheets(4).Name = "009"

    Thank you

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    along the lines of:?
    Dim rng As Range
    Sheets("Chris Error Code List").Select
    Set rng = Cells.Find(What:="009", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not rng Is Nothing Then
      rng.Offset(columnOffset:=1).Activate
      Selection.ShowDetail = True
      ActiveSheet.Name = "009"
    End If
    Lots of error codes? Perhaps (untested):
    Dim rng As Range
    ErrorCodeList = Array("009", "008", "007", "666", "111")
    For Each ErrorCode In ErrorCodeList
      Set rng = Sheets("Chris Error Code List").Cells.Find(What:=ErrorCode, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
      If Not rng Is Nothing Then
        rng.Offset(columnOffset:=1).ShowDetail = True
        ActiveSheet.Name = ErrorCode
      End If
    Next  'ErrorCode
    Last edited by p45cal; 07-25-2016 at 04:24 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    That works perfectly.

    Thank you :-)

Posting Permissions

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