Chesca
Chesca

Reputation: 1

Why does my excel stop responding when I try to run my VBA code?

Updated my question. I put a flowchart and screenshots of my sheets so you guys can understand better.

Chart

Sheet

When I start to run this, Excel stops responding. I can't seem to find where the bug is. I hope someone can help! I researched about VBA codes but I think something is still lacking?

Sub F110Loop()

Dim x As Integer 'current amount
Dim y As Integer
Dim d As Double 'delta between Disbursement date and Cheque Release date
Dim Current As Integer
Dim Least As Integer
Dim Dis As Worksheet
Dim Cheque As Worksheet
Dim wb As Workbook

Set wb = ThisWorkbook
Set Dis = wb.Sheets("Disbursements")
Set Cheque = wb.Sheets("Cheque Info")
wb.Activate

For x = 4 To 600
    Do While Dis.Cells(x, 9).Value > 1
        'IF same amount, get row number to get corresponding date, reference that date
        For y = 3 To 600
            If Dis.Cells(x, 6).Value = Cheque.Cells(y, 5).Value Then
                'THEN get delta
                Current = Dis.Cells(x, 4).Value -Cheque.Cells(y, 2)
                'IF current is less than the least delta
            ElseIf Current < Least Then
                'THEN update new value of delta
                Current = Least
            Else
                'copy paste the date (from the least delta row)
                Cheque.Cells(y, 2).Copy Destination:=Dis.Cells(x, 8)
            End If
        Next y
    Loop
Next x

End Sub

Upvotes: 0

Views: 77

Answers (2)

Nofey
Nofey

Reputation: 21

you have to do something like:

x = 4
Do while Dis.Cells(x,9).value > 1
   x = x + 1
loop

Upvotes: 1

Charles Williams
Charles Williams

Reputation: 23540

Probably you have an infinite loop because you never change Dis.Cells(x, 9)

Do While Dis.Cells(x, 9).Value > 1
' make no change to Dis.Cells(x, 9)
Loop

Upvotes: 4

Related Questions