Results 1 to 2 of 2

Function If Else needs to cater for zero value

Threaded View

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Function If Else needs to cater for zero value

    This function works perfectly to search for a string - if found in a range sum the two values and calculate a percentage contribution to the total

    However it takes the Else statement of equal to 1 when I want to enter "0" if the revenue value is equal to zero

    I tried the below but it does not replace the 1 with a zero

    Any help appreciated
    Function Unit(Revenue)
    Dim RngX As Range
    Dim Reg As String
    Dim TtlRevenue As Integer
    
    
    Reg = Revenue.Offset(0, -5).Value
    
        Set RngX = Worksheets(1).Range("B81:B90").Find(Reg, lookat:=xlPart)
            If Not RngX Is Nothing Then
                TtlRevenue = Revenue + RngX.Offset(0, 5).Value
                    Unit = Application.RoundUp(Revenue / TtlRevenue, 1)
            Else: Unit = 1
            End If
    If revenue =0 Then 
    Unit = 0
    End If
    
    End Function
    Last edited by nigelog; 02-21-2018 at 11:49 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 04-23-2017, 12:04 AM
  2. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  3. VBA code for custom function that returns detail results of array function
    By onechipshot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2015, 06:30 PM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  6. Adjusting prizes to cater for ties
    By Max in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-12-2005, 10:05 AM
  7. Cater for unregistered DLL
    By Peter T in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-13-2005, 02:05 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