+ Reply to Thread
Results 1 to 5 of 5

Help to amend code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Help to amend code

    Hello,

    The below code does the following:

    Any cell with a 0 in the specified range gets #N/A put in the cell to the right of it.

    How do I change it so:

    Any cell with a 0 in the specified range gets #N/A put in the cell to the right of it UNLESS it has a value bigger than 0, in which case it gets a formula put in it?

    Sub IfZero2()
    Dim myRange As Range
    
    For Each myRange In Sheets("Chart Data").Range("B15:B31")
     If myRange = 0 Then
      myRange.Offset(0, 1) = "#N/A"
     End If
    Next myRange
    End Sub

  2. #2
    Registered User
    Join Date
    06-17-2012
    Location
    Australia
    MS-Off Ver
    MS Office 365
    Posts
    40

    Re: Help to amend code

    Try per below. Untested however.
    Sub IfZero2()
    Dim myRange As Range
    
    For Each myRange In Sheets("Chart Data").Range("B15:B31")
      Select Case myRange
        Case Is = 0
          myRange.Offset(0, 1) = "#N/A"
        Case Is > 0
          myRange.Offset(0, 1).Formula = ""  ' //Enter formula inside quotation marks
      End Select
    Next myRange
    End Sub
    Last edited by bradl822; 06-15-2015 at 07:21 AM.

  3. #3
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Help to amend code

    Thank you, however I have noticed 1 thing that is different to what I first thought. The formula is different in each cell, because it's a formula to work out the cumulative amount. How can I do this please?

  4. #4
    Registered User
    Join Date
    06-17-2012
    Location
    Australia
    MS-Off Ver
    MS Office 365
    Posts
    40

    Re: Help to amend code

    Sub IfZero2()
    Dim myRange As Range
    
        For Each myRange In Sheets("Chart Data").Range("B15:B31")
          Select Case myRange
            Case Is = 0
              myRange.Offset(0, 1) = "#N/A"
            Case Is > 0
              myRange.Offset(0, 1).Formula = "=SUM(B15:" & myRange.Address & ")"  ' //Enter formula inside quotation marks
          End Select
        Next myRange
    End Sub

  5. #5
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Help to amend code

    Thank you...

+ 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] Amend Code
    By Burt_100 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-23-2015, 05:58 AM
  2. Amend Code for Printing
    By mdot218 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2011, 08:34 PM
  3. Amend Code help
    By VBA Noob in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-21-2006, 03:16 PM
  4. Amend code
    By VBA Noob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2006, 05:32 PM
  5. Amend the Code
    By shan_in_dubai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2005, 04:36 AM

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