Sub Quiz()
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:D" & LastRow).ClearContents
Risultato = Int(InputBox("inserisci valore"))
rad = Sqr(Risultato)
If rad <> Int(rad) Then MsgBox "Radice quadra non intera": Exit Sub
riga = 0
For i = Risultato - 2 To 1 Step -1
If Risultato / i = Int(Risultato / i) Then
riga = riga + 1
Cells(riga, 1).Value = Risultato / i
End If
Next i
riga1 = 0
For i = 1 To riga
risultato1 = Risultato / Cells(i, 1).Value
If risultato1 = Int(risultato1) Then
If risultato1 < rad Or risultato1 = rad Then
riga1 = riga1 + 1
Cells(riga1, 2).Value = risultato1
ElseIf risultato1 > rad Then
If (Risultato / Cells(i, 1).Value) / 2 = Int((Risultato / Cells(i, 1).Value) / 2) Then
riga1 = riga1 + 1
Cells(riga1, 2).Value = (Risultato / Cells(i, 1).Value) / 2
Else
riga1 = riga1 + 1
Cells(riga1, 2).Value = (Risultato / Cells(i, 1).Value) / 3
End If
End If
End If
Next i
For c = 1 To riga
Cells(c, 3).Value = Risultato / Cells(c, 1).Value
Cells(c, 3).Value = Cells(c, 3).Value / Cells(c, 2).Value
Next c
Ris = 1
For i = 1 To riga
Risultato2 = Cells(i, 1).Value + Cells(i, 2).Value + Cells(i, 3).Value
For n = 1 To riga
Confronto = Cells(n, 1).Value + Cells(n, 2).Value + Cells(n, 3).Value
If Risultato2 = Confronto Then
Ris = Ris + 1
End If
Next n
If Ris > 2 Then
Cells(i, 4) = Cells(i, 1).Value & Cells(i, 2).Value & Cells(i, 3).Value
End If
Ris = 1
Next i
For i = 1 To riga
If Cells(i, 4) <> "" Then
MinimoV = Range("A" & i & ":C" & i) '.Value
Minimo = Application.WorksheetFunction.Min(MinimoV)
If Application.WorksheetFunction.CountIf(Range("A" & i & ":C" & i), Minimo) = 1 Then
MsgBox "Combinazione trovata " & Cells(i, 4).Value
End If
End If
Next i
End Sub
|