
Option Explicit
Sub AmboFrequente()
Dim ambo As String, ramb As Integer
Dim rig As Integer, urig As Long
Dim i As Long
Dim rng As Range, c As Range, xxx As Range
Set rng = Range("D14:H621")
Range("A:B").ClearContents
'For Each c In rng
'c.Value = Int((90 - 1 + 1) * Rnd + 1)
'Next c
urig = Range("H" & Rows.Count).End(xlUp).Row
i = 2
Cells(1, 1) = "AMBI"
Cells(1, 2) = "USCITE"
'Ambi
For rig = 14 To urig
For ramb = 5 To 8
If Cells(rig, 4).Value > Cells(rig, ramb).Value Then
ambo = Cells(rig, 4).Value & " - " & Cells(rig, ramb).Value
Else
ambo = Cells(rig, ramb).Value & " - " & Cells(rig, 4).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next ramb
For ramb = 6 To 8
If Cells(rig, 5).Value > Cells(rig, ramb).Value Then
ambo = Cells(rig, 5).Value & " - " & Cells(rig, ramb).Value
Else
ambo = Cells(rig, ramb).Value & " - " & Cells(rig, 5).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next ramb
For ramb = 7 To 8
If Cells(rig, 6).Value > Cells(rig, ramb).Value Then
ambo = Cells(rig, 6).Value & " - " & Cells(rig, ramb).Value
Else
ambo = Cells(rig, ramb).Value & " - " & Cells(rig, 6).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next ramb
Next rig
Columns("A:B").Select
Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select
ambo = [A2]
Application.Wait Now + TimeValue("00:00:01")
'Range("A:B").ClearContents
MsgBox "L'Ambo più frequente è il " & ambo & ""
End Sub
|
Option Explicit
Sub TernoFrequente()
Dim Terno As String, Tern As Integer
Dim rig As Integer, urig As Long
Dim i As Long
Dim rng As Range, c As Range, xxx As Range
Set rng = Range("F14:J53")
Range("C:D").ClearContents
'For Each c In rng
'c.Value = Int((90 - 1 + 1) * Rnd + 1)
'Next c
urig = Range("J" & Rows.Count).End(xlUp).Row
i = 3
Cells(1, 3) = "TERNI"
Cells(1, 4) = "USCITE"
'Ambi
For rig = 14 To urig
For Tern = 8 To 10
If Cells(rig, 6).Value > Cells(rig, Tern).Value Then
Terno = Cells(rig, 6).Value & " - " & Cells(rig, Tern).Value
Else
Terno = Cells(rig, Tern).Value & " - " & Cells(rig, 6).Value
End If
Set xxx = Range("C:C").Find(Terno, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 3) = Terno
Cells(i, 4) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next Tern
Next rig
Columns("C:D").Select
Selection.Sort Key1:=Range("D1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("C1").Select
Terno = [C2]
Application.Wait Now + TimeValue("00:00:01")
'Range("C:D").ClearContents
MsgBox "Il terno più frequente è il " & Terno & ""
End Sub
|
Sub trombolo()
Dim ambo As String, ramb As Integer
Dim rig As Integer, urig As Long
Dim i As Long
Dim rng As Range, c As Range, xxx As Range
Set rng = Range("D14:H621")
Range("A:B").ClearContents
'For Each c In rng
'c.Value = Int((90 - 1 + 1) * Rnd + 1)
'Next c
urig = Range("H" & Rows.Count).End(xlUp).Row
i = 2
Cells(1, 1) = "AMBI"
Cells(1, 2) = "USCITE"
'Ambi
For rig = 14 To urig
For ramb = 5 To 8
If Cells(rig, 4).Value > Cells(rig, ramb).Value Then
ambo = Cells(rig, 4).Value & "_" & Cells(rig, ramb).Value
Else
ambo = Cells(rig, ramb).Value & "_" & Cells(rig, 4).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next ramb
For ramb = 6 To 8
If Cells(rig, 5).Value > Cells(rig, ramb).Value Then
ambo = Cells(rig, 5).Value & "_" & Cells(rig, ramb).Value
Else
ambo = Cells(rig, ramb).Value & "_" & Cells(rig, 5).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next ramb
For ramb = 7 To 8
If Cells(rig, 6).Value > Cells(rig, ramb).Value Then
ambo = Cells(rig, 6).Value & "_" & Cells(rig, ramb).Value
Else
ambo = Cells(rig, ramb).Value & "_" & Cells(rig, 6).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next ramb
If Cells(rig, 7).Value > Cells(rig, 8).Value Then
ambo = Cells(rig, 7).Value & "_" & Cells(rig, 8).Value
Else
ambo = Cells(rig, 8).Value & "_" & Cells(rig, 7).Value
End If
Set xxx = Range("A:A").Find(ambo, lookat:=xlWhole)
If xxx Is Nothing Then
Cells(i, 1) = ambo
Cells(i, 2) = 1
i = i + 1
Else
xxx.Offset(, 1).Value = xxx.Offset(, 1).Value + 1
End If
Next rig
'Columns("A:B").Select
' Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlGuess, _
' OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
' DataOption1:=xlSortNormal
'Range("A1").Select
'ambo = [A2]
'MsgBox "L'Ambo più frequente è il " & ambo & "! Glia altri rimarranno un segreto! ^_^"
End Sub
|
'determino l'ultima riga piena della colonna "H"
urig = Range("H" & Rows.Count).End(xlUp).Row
For rig = 14 To urig
'esegue istruzioni a partire dalla riga 14 sino a urig (ultima riga piena)
next rig |
Sub petolo() On Error GoTo error Dim rng1 As Range Dim ind1 As String, ind2 As String ind1 = [F8].Value ind2 = [F9].Value Set rng1 = Range(ind1, ind2) rng1.Value = "Antonno Petolo" Cells.EntireColumn.AutoFit Exit Sub error: MsgBox "valore non compatibile" End Sub |
Set rng = [F8:F9]
Set rng = Range("F8:F9")
