Results 1 to 11 of 11

Thread: [RESOLVED] Calculating Networkdays with a condition

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    34

    Resolved [RESOLVED] Calculating Networkdays with a condition

    I was given the following code to automate entering the networkdays formula is a monthly report I have to do. I have attached a copy of the workbook I am working with and the code I currently have is...

    Code:
    Sub Networkdays()
        Dim wks         As Worksheet
        Dim cell        As Range
    
        Set wks = Worksheets("SLA Calculations")
    
        With wks
            If .Range("N1").Value = "Stratix Diagnostics TAT" Then
                For Each cell In .Range("N2", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, "N"))
                    If IsEmpty(cell.Value2) Then
                    cell.FormulaR1C1 = "=NETWORKDAYS(RC[-3], RC[-2])"
                    End If
                    If Not IsEmpty(cell.Value2) Then
                    cell.FormulaR1C1 = "=NETWORKDAYS(RC[-3], RC[-2])"
                    End If
                Next cell
            End If
        End With
        With wks
            If .Range("T1").Value = "Moto TAT" Then
                For Each cell In .Range("T2", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, "T"))
                    If IsEmpty(cell.Value2) Then
                    cell.FormulaR1C1 = "=NETWORKDAYS(RC[-5], max(RC[-2],RC[-4]))"
                    End If
                    If Not IsEmpty(cell.Value2) Then
                    cell.FormulaR1C1 = "=NETWORKDAYS(RC[-5], max(RC[-2],RC[-4]))"
                    End If
                Next cell
            End If
        End With
        With wks
            If .Range("W1").Value = "Stratix Repair TAT" Then
                For Each cell In .Range("W2", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, "W"))
                    If IsEmpty(cell.Value2) Then
                    cell.FormulaR1C1 = "=NETWORKDAYS(max(RC[-5],RC[-7]), RC[-1])"
                    End If
                    If Not IsEmpty(cell.Value2) Then
                    cell.FormulaR1C1 = "=NETWORKDAYS(max(RC[-5],RC[-7]), RC[-1])"
                    End If
                Next cell
            End If
        End With
    End Sub
    The problem I have is that I would like to alter this formula with a condition. That condition being if the device has repeat repair data then subtract 4 from the networkdays formula and if no data in repeat repairs then subtract 2.

    Ex.
    Device A goes to vendor for repair, vendor returns after repaired, then device has to go back to vendor again and then vendor returns device, the formula I have been manually entering would be...

    =Networkdays(O2,R2)-4

    Then Device B goes to vendor and is returned from vendor and then returned to the customer and the formula I entered for this is...

    =Networkdays(O2,P2)-2

    So how do I alter the above code to reflect these conditions?


    Thanks!!!!
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width