VBA error

chintan desai

New Member
Joined
Sep 20, 2011
Messages
8
Hi,

I have written a program but for some reason when I run it, it keeps running until I manually end it. Weirdly, when I end it the program has actually worked but for some reason it doesn't stop itself.


Do

For i = 3 To 758

Range("B" & i).Value = i


Range("G" & i).FormulaR1C1 = "=IF(RC[-5]=R[-1]C[-5],IF(RC[-4]=""Buy"",R[-1]C+RC[-2],R[-1]C-RC[-2]),RC[-2])"


Next i


Loop Until (Range("F" & i).Value <> "") And (Range("F" & i).Value <> " ")



Can anyone tell me why this program works, but doesn't end by itself? Thanks!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I have two theories, but I'm not sure of either.

Do you have an end sub somewhere after?

and

I think because the Loop Until values are the same:

Loop Until (Range("F" & i).Value <> "") And (Range("F" & i).Value <> " ")
 
Upvote 0
Hi,

I do have an End sub at the end. In addition, if i removed the repeated loop, the function still works but need to manually end it. Also when asked to debug, it high lights [ Range("B" & i).value=1 ]. I don't know the reasoning behind that either. Thanks!
 
Upvote 0
In the original post you have value=i and now value=1


What's in the sub? Maybe that could be it?
 
Upvote 0
Sorry, meant to type i instead of 1, so it is "i". And it's:

Sub CumulativePos()




Do

For i = 3 To 758

Range("B" & i).Value = i


Range("G" & i).FormulaR1C1 = "=IF(RC[-5]=R[-1]C[-5],IF(RC[-4]=""Buy"",R[-1]C+RC[-2],R[-1]C-RC[-2]),RC[-2])"


Next i


Loop Until (Range("F" & i).Value <> "")





End Sub


Don't know whats wrong with the sub.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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