Posted on 2014-08-11
Last Modified: 2014-08-11

I need to wrap the below action in an IF

Basically IF Column B contains "Summary" then......

Else skip this part of code.....

Im getting a debug when summary doesnt exist


    Selection.Find(What:="Summary", After:=ActiveCell, LookIn:=xlFormulas _
        , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    With ActiveCell
    .Offset(0, -1).ClearContents
    .Offset(1, -1).ClearContents
    End With

Open in new window

Question by:Seamus2626
    LVL 18

    Accepted Solution

        Dim rngSummary  As Range
        On Error Resume Next
        Set rngSummary = Nothing
        Set rngSummary = Columns("B:B").Find(What:="Summary", After:=ActiveCell, LookIn:=xlFormulas _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
        On Error GoTo 0
        If Not rngSummary Is Nothing Then
            With rngSummary
                .Offset(0, -1).ClearContents
                .Offset(1, -1).ClearContents
            End With
        End If

    Open in new window


    Author Closing Comment


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I've recently been in need of an Excel macro that could add a letter before the text on multiple cells in an Excel document. My English is as it is, so I will try explain what it does diffrently. If you have an excel document with 2000 rows an…
    INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now