+ Reply to Thread
Results 1 to 2 of 2

Expanding on existing VBA code

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2009
    Location
    pittsburgh, pa
    MS-Off Ver
    Excel 2007
    Posts
    52

    Expanding on existing VBA code

    I have the following code:

    If Application.RoundDown(Left_Cell, 2) = Application.RoundDown(Cp_1, 2) Then SectionBottom = Cp_1 - (O_1 / 12): Exit Function
    What I would like for it to do is to continue to execute the above function if O_1 > 0 or O_1 < 0, but if O_1 = 0, then to ignore the code. So in effect, if O_1 = 0, exit the function without assigning a value to SectionBottom.

    Any advice?

    Thanks.

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Expanding on existing VBA code

    if not O_1 = 0
    (your line without the : exit function)
    end if
    exit function
    Code's easier to read (hence debug) if you break out your ifs into blocks, so I'd actually recommend:
    if not O_1 = 0
    If Application.RoundDown(Left_Cell, 2) = Application.RoundDown(Cp_1, 2) Then
    SectionBottom = Cp_1 - (O_1 / 12)
    end if
    end if
    exit function
    I'd also indent it, but I can't do that without easily using the VBE and without any context I can't really test what I'm telling you

    HTH
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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