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.
 

dafan

Well-known Member
Joined
May 6, 2008
Messages
692
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.
 

Forum statistics

Threads
1,081,802
Messages
5,361,388
Members
400,628
Latest member
ganeshkhatri

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top