+ Reply to Thread
Results 1 to 14 of 14

How to skip blank cells in Function for Rank in VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-18-2007
    Posts
    74

    How to skip blank cells in Function for Rank in VBA?

     Function RankSum(InRange, OutRange, RankRange, SegmentStartTime, SegmentMinutes)
    For Each Cell In InRange
        StartTime = Cell
        FinishTime = Cell.Offset(0, OutRange.Column - InRange.Column)
        If StartTime - (SegmentMinutes / (24 * 60)) < SegmentStartTime And FinishTime >= SegmentStartTime + (SegmentMinutes / (24 * 60)) - 0.0000000001 Then
            RankSum = RankSum + Cell.Offset(0, RankRange.Column - InRange.Column)
        End If
    Next Cell
    End Function
    how would i get this module to do nothing if certain text is entered in the box
    Last edited by VBA Noob; 05-23-2007 at 01:29 PM.

  2. #2
    Registered User
    Join Date
    05-04-2006
    Posts
    24

    if statement

    why wouldnt you use an if statement?

    Function RankSum(InRange, OutRange, RankRange, SegmentStartTime, SegmentMinutes)
    For Each Cell In InRange
    StartTime = Cell
    FinishTime = Cell.Offset(0, OutRange.Column - InRange.Column)
    if StartTime = "set value" then
    else
    If StartTime - (SegmentMinutes / (24 * 60)) < SegmentStartTime And FinishTime >= SegmentStartTime + (SegmentMinutes / (24 * 60)) - 0.0000000001 Then
    RankSum = RankSum + Cell.Offset(0, RankRange.Column - InRange.Column)
    End If
    end if
    Next Cell
    End Function

  3. #3
    Registered User
    Join Date
    05-18-2007
    Posts
    74
    im not real familiar with this code? can you tell me what what "set value" or would be?

  4. #4
    Registered User
    Join Date
    05-04-2006
    Posts
    24

    set value

    set value would be the text you are wanting it to avoid.. If i wanted to avoid all start times that were 10:00 then i would put
    if StartTime = "10:00" then

  5. #5
    Registered User
    Join Date
    05-18-2007
    Posts
    74
    ok, i thought so...so as of now. i have
    
    Function RankSum(InRange, OutRange, RankRange, SegmentStartTime, SegmentMinutes)
    For Each Cell In InRange
        StartTime = Cell
        FinishTime = Cell.Offset(0, OutRange.Column - InRange.Column)
        If StartTime = "HOL" Or "VAC" Or "FMLA" Then
        StartTime = 0
        Else
        If StartTime - (SegmentMinutes / (24 * 60)) < SegmentStartTime And FinishTime >= SegmentStartTime + (SegmentMinutes / (24 * 60)) - 0.0000000001 Then
            RankSum = RankSum + Cell.Offset(0, RankRange.Column - InRange.Column)
        End If
        End If
    Next Cell
    End Function
    thats still outputting an error
    Last edited by VBA Noob; 05-23-2007 at 01:29 PM.

  6. #6
    Registered User
    Join Date
    05-04-2006
    Posts
    24

    yes, try this..

    you are setting it equal to 0, but then you are not doing anything as the rest of your process is part of the else.. try this.

    Please use code tags as it is the forum rules.

    Function RankSum(InRange, OutRange, RankRange, SegmentStartTime, SegmentMinutes)
    For Each Cell In InRange
    StartTime = Cell
    FinishTime = Cell.Offset(0, OutRange.Column - InRange.Column)
    If StartTime = "HOL" Or "VAC" Or "FMLA" Then
    StartTime = 0
    end if
    If StartTime - (SegmentMinutes / (24 * 60)) < SegmentStartTime And FinishTime >= SegmentStartTime + (SegmentMinutes / (24 * 60)) - 0.0000000001 Then
    RankSum = RankSum + Cell.Offset(0, RankRange.Column - InRange.Column)
    End If
    
    Next Cell
    End Function

+ 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