Loop not working in VBA post i value 1482

Bolo bolo

New Member
Joined
Apr 13, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub Case_Automation()

Dim a As Long
Dim b As String
Dim c As Long
Dim d As Long
Dim e As Long
Dim f As Long
Dim g As Long
Dim h As Long
Dim z As Long
Dim j As Long
Dim k As Long


For z = 10 To 50003


a = Cells(z, 8).Value
b = Cells(z, 27).Value
c = Cells(z, 14).Value
d = Cells(z, 18).Value
e = Cells(z, 28).Value
f = Cells(z, 30).Value
g = Cells(z, 36).Value
h = Cells(z, 38).Value
j = Cells(z, 31).Value
k = Cells(z, 33).Value





Cells(z, 1) = Case_Number(a, b, c, d, e, f, g, h, j, k)


Next


End Sub


Function Case_Number(PO_Date As Long, PO_Status As String, PO_Quantity As Long, PO_Value As Long, Still_to_be_delivered_Quantity As Long, Still_to_be_delivered_value As Long, Delivered_Quantity As Long, Delivered_value As Long, Still_to_be_invoiced_quantity As Long, Still_to_be_invoiced_value As Long)
         '             a                  b                       c                       d                                          e                                f                            g                   h                                      j                        k



Dim z As String
Dim inter As Integer



'"Still to be Delievered
'Qty = NIL
'Value = NIL
'Still to be Invoiced = NIL"


  



If PO_Status = "Blocked" Then


    If Still_to_be_deliverd_quantity = 0 Then
        If Still_to_be_delivered_value = 0 Then
            If Still_to_be_invoiced_quantity = 0 Then
                z = "Case 1"
                Case_Number = z
            End If
        End If
    End If
End If
  
  
If PO_Status = "Deleted" Then


    If Still_to_be_deliverd_quantity = 0 Then
        If Still_to_be_delivered_value = 0 Then
            If Still_to_be_invoiced_quantity = 0 Then
                z = "Case 2"
                Case_Number = z
            End If
        End If
    End If
End If
  
  


If PO_Status = "Open" Then


    If PO_Date <= 43465 Then
        z = "Case 9"
        Case_Number = z
    End If

       
    If PO_Date > 43465 Then
         z = "Case 10"
         Case_Number = z
          
         End If
 

    If PO_Quantity = Still_to_be_delivered_Quantity Then
        If Still_to_be_delivered_value = PO_Value Then
            If Delivered_value = 0 Then
                z = "Case 3"
                Case_Number = z
                Exit Function
            End If
        End If
    End If
  
    If Still_to_be_delivered_Quantity = PO_Quantity Then
        If Delivered_Quantity = 0 Then
            If Still_to_be_delivered_value = 0 Then
                If Delivered_value = PO_Value Then
                    z = "Case 4"
                    Case_Number = z
                    Exit Function
                End If
         End If
        End If
    End If

    If Still_to_be_delivered_Quantity = 0 Then
            If Still_to_be_delivered_value = 0 Then
                If Delivered_value = PO_Value Then
                    z = "Case 5"
                    Case_Number = z
                    Exit Function
                End If
            End If
    End If
  
  
    If Still_to_be_delivered_Quantity = 0 Then
        If Delivered_value = PO_Value Then
            If Delivered_value = 0 Then
                    z = "Case 6"
                    Case_Number = z
                    Exit Function
                End If
            End If
    End If

    If Still_to_be_delivered_Quantity = 0 Then
        If Delivered_value = PO_Value Then
            If Delivered_value = 0 Then
                    z = "Case 6"
                    Case_Number = z
                    Exit Function
            End If
        End If
    End If
    If Still_to_be_delivered_Quantity = 0 Then
        If Delivered_value < PO_Value Then
            If Delivered_value < PO_Value Then
                    z = "Case 7"
                    Case_Number = z
                    Exit Function
             End If
           End If
    End If
  

    If Still_to_be_delivered_Quantity > 0 Then
        If Delivered_Quantity > 0 Then
            If Still_to_Delivered_value = 0 Then
                If Delivered_value = PO_Value Then
                    z = "Case 8"
                    Case_Number = z
                    Exit Function
                End If
                End If
        End If
    End If
  
  
  

  

 
      
End If


End Function

Please help...."i" value stops after 1482...till there loop rund fine
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Accessing the worksheet multiple times in a loop is always going to be very slow and this might be the cause of your problem try this simple modification which at the very least will make the macro run a thousand times faster ( I do mean 1000 times faster at least);
VBA Code:
Sub Case_Automation()
Dim inarr() As Variant
Dim a As Long
Dim b As String
Dim c As Long
Dim d As Long
Dim e As Long
Dim f As Long
Dim g As Long
Dim h As Long
Dim z As Long
Dim j As Long
Dim k As Long

inarr = Range(Cells(1, 1), Cells(50003, 38))
For z = 10 To 50003


a = inarr(z, 8)
b = inarr(z, 27)
c = inarr(z, 14)
d = inarr(z, 18)
e = inarr(z, 28)
f = inarr(z, 30)
g = inarr(z, 36)
h = inarr(z, 38)
j = inarr(z, 31)
k = inarr(z, 33)






Cells(z, 1) = Case_Number(a, b, c, d, e, f, g, h, j, k)


Next
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,667
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top