+ Reply to Thread
Results 1 to 2 of 2

If Then Statement Not Working

  1. #1
    Registered User
    Join Date
    04-27-2015
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    1

    If Then Statement Not Working

    I am trying to clear any formulas which result in a value of 0 or "" in a range which is called "_Stacking Plan". The code either stops on the If statement:

    Dim c As Range
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    With ThisWorkbook.ActiveSheet.Range("_StackingPlan"): Rem adjust
    For Each c In ActiveSheet.Range("_StackingPlan")
    With c
    If c = 0 Then c.ClearContents
    End With
    Next c
    End With

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

    OR, if I add an End If, I get a "compile error: End If without block If":

    Dim c As Range
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    With ThisWorkbook.ActiveSheet.Range("_StackingPlan"): Rem adjust
    For Each c In ActiveSheet.Range("_StackingPlan")
    With c
    If c = 0 Then c.ClearContents
    End If
    End With
    Next c
    End With

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

    I am not a well-versed VBA programmer, so it could be something “obvious”. But, I have tried all kinds of variations on this code. Nothing seems to work.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: If Then Statement Not Working

    Try remove the inner With pair

    Please Login or Register  to view this content.
    Martin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Using = and <> in IF(AND statement not working
    By bocrad75 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-15-2014, 12:39 PM
  2. Working While Statement Stops Working
    By Verbaruab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2011, 05:58 PM
  3. If statement not working
    By lit2003 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-21-2008, 04:03 PM
  4. If statement not working
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-15-2005, 06:40 PM
  5. [SOLVED] For Each Statement still not working
    By Jacqui in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-02-2005, 06:17 PM

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