?
Solved

VBA IF

Posted on 2014-08-11
2
Medium Priority
?
104 Views
Last Modified: 2014-08-11
Hi,

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

Thanks



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

Open in new window

0
Comment
Question by:Seamus2626
2 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 2000 total points
ID: 40252646
    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
            .ClearContents
            .Offset(0, -1).ClearContents
            .Offset(1, -1).ClearContents
        End With
    End If

Open in new window


Kris
0
 

Author Closing Comment

by:Seamus2626
ID: 40252650
Thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

862 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