How to loop and print if the condition becomes negative

lagsca

New Member
Joined
Aug 18, 2008
Messages
2
How to test a loop and print if the condition becomes negative?

Example:

I like to loop Cell B1 from values 1 to 500.

Cell B8 output changes depending on the value of Cell B1.

When Cell B8 becomes negative, I like to print it. I like to print each negative until the values reach 500 in cell B1.

Thank you for your help.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This will print all negative values in B8 in column C from 1 to x (where x = amount of negative values that pass in B8 when looping from 1 to 500).

Code:
Sub Test()
 
j = 0
For i = 1 To 500
    Range("B1").Value = i
    If Range("B8").Value < 1 Then
        j = j + 1
        Range("C" & j).Value = Range("B8").Value
    End If
Next
 
End Sub

I used an easy =IF(MOD(B1,10)=0,-1,1) in B8 so I got a list of 50 times -1 in C1:C50.

HTH.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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