Row Calculation Sub Gets Application Error

Morierus

New Member
Joined
Jul 9, 2011
Messages
5
Hello,

I have written a sub that calculates the number of rows in which a certain string is mentioned, and subsequently outputs another string if the number of rows is greater than or equal to 5. However, upon running it, I get an error that says:

Run-time error '1004':
Application-Defined or Object-Defined Error

However, I am unable to see how the line indicated upon debugging the code is in any way wrong. I'm hoping you can help me. The code I have written is as follows:

Sub Min_Dates()

Dim i As Long
Dim j As Long: j = 2
Dim m As Long: m = 1
Dim d As Long


Dim b As String
Dim a As String


Do

i = j

If i = 10 * m Then

m = m + 1
Cells(1, 80).Value = i

End If

Do

b = Cells(j, 1).Value
a = Cells(j + 1, 1).Value
j = j + 1

Loop Until a <> b

d = j - i

If d >= 5 Then

Cells(i, 79).Value = "Suitable"

End If

j = j + 1

Loop Until Cells(j + 1, 1).Value = "END"

End Sub


The line in yellow is what the debugging says must be correct. Can anyone spot what is wrong in the code?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Have you checked the value of j when the code errors?
 
Upvote 0
Yeah, it is 1048576. This value holds even when I change the data type to Double. Also, I'm confused why the variable reaches this value, as the final row is 1012. Do you have any idea what it can be?
 
Upvote 0
Hi

Perhaps in this line you will never meet the condition -
Code:
Loop Until Cells(j + 1, 1).Value = "END"

because you have incremented variable j in the previous line.

hth
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

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