G
G
Georgy Kuznetsov2020-10-27 22:44:04
Macros
Georgy Kuznetsov, 2020-10-27 22:44:04

How to collect all values ​​that satisfy the specified conditions?

It is necessary to collect the number of such values ​​​​in the textBox TB1 from position B2 to Y92 that would be greater than the value in cell Z93, but less than in AA93

I wrote here what I could, but of course it does not work (when debugging the code, I realized that the condition in the loop always false)

Private Sub CommandButton1_Click()
Dim a As Integer
For i = 2 To 25
For ii = 2 To 92
If (Cells(i, ii) > Cells(26, 93) And Cells(i, ii) < Cells (27, 93)) Then
a = a + 1
TB1.Text = a
End If
Next
Next
End Sub

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2020-10-27
@JoeSmith3100

Your i should change from 2 to 92, and ii from 2 to 25, because the first argument is Cellsa string and the second argument is a column.
The rest of the rules should work.
You can add Debug.print Cells(i,ii)to output values ​​​​to the console and see what the comparison instruction operates
To see the console Ctrl + G or the View->Immediate Window menu

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question