
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
'---------------------------------------------------------------------------------------
' Procedure : CheckCash
' Author : scossa
' Date : 08/04/2014
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Sub CheckCash()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim cella As Range
Dim cPaym As Collection
Dim vPaym As Variant
Dim nMax As Currency
Dim nMin As Currency
Dim nToll As Currency
Dim j As Long
Dim bCalc As XlCalculation
On Error GoTo CheckCash_Error
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Foglio1")
Set rng = ws.Range("H4:H" & ws.Cells(Rows.Count, 8).End(xlUp).Row)
Set cPaym = New Collection
nToll = ws.Range("P1").Value
rng.Offset(, 7).ClearContents
For Each cella In rng.Offset(, 8)
With cella
cPaym.Add Array(.Value, .Offset(0, 1).Value)
End With
Next cella
For Each cella In rng
With cella
nMin = .Value - nToll
nMax = .Value + nToll
j = 0
For Each vPaym In cPaym
j = j + 1
If (vPaym(0) = .Value) Or (vPaym(0) >= nMin And vPaym(0) <= nMax) Then
cella.Offset(0, 7) = vPaym(1)
cPaym.Remove j
Exit For
End If
Next
End With
Next cella
On Error GoTo 0
'Exit Sub
CheckCash_Error:
Set wb = Nothing
Set ws = Nothing
Set rng = Nothing
Set cPaym = Nothing
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description, vbCritical, "ERRORE"
End If
End Sub
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
'---------------------------------------------------------------------------------------
' Procedure : CheckCash
' Author : scossa
' Date : 08/04/2014
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Sub CheckCash()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim cella As Range
Dim cPaym As Collection
Dim vPaym As Variant
Dim cCash As Collection
Dim nMax As Currency
Dim nMin As Currency
Dim nToll As Currency
Dim j As Long
Dim k As Long
Dim bCalc As XlCalculation
On Error GoTo CheckCash_Error
With Application
bCalc = .Calculation
.Calculation = xlCalculationManual
End With
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Foglio1")
Set rng = ws.Range("H4:H" & ws.Cells(Rows.Count, 8).End(xlUp).Row)
Set cCash = New Collection
Set cPaym = New Collection
nToll = ws.Range("P1").Value
rng.Offset(, 7).ClearContents
For Each cella In rng
With cella
cCash.Add Array(.Value, 0)
End With
Next cella
For Each cella In rng.Offset(, 8)
With cella
cPaym.Add Array(.Value, .Offset(0, 1).Value)
End With
Next cella
For k = 1 To cCash.Count
j = 0
For Each vPaym In cPaym
j = j + 1
If (vPaym(0) = cCash.Item(k)(0)) Then
cCash.Add Array(cCash(k)(0), vPaym(1)), after:=k
cCash.Remove k
cPaym.Remove j
Exit For
End If
Next
Next k
For k = 1 To cCash.Count
If cCash(k)(1) = 0 Then
nMin = cCash(k)(0) - nToll
nMax = cCash(k)(0) + nToll
j = 0
For Each vPaym In cPaym
j = j + 1
If (vPaym(0) >= nMin And vPaym(0) <= nMax) Then
cCash.Add Array(cCash(k)(0), vPaym(1)), after:=k
cCash.Remove k
cPaym.Remove j
Exit For
End If
Next
End If
Next k
For j = 1 To cCash.Count
rng.Cells(j, 1).Offset(0, 7) = cCash(j)(1)
Next j
On Error GoTo 0
'Exit Sub
CheckCash_Error:
Set wb = Nothing
Set ws = Nothing
Set rng = Nothing
Set cPaym = Nothing
Set cCash = Nothing
Application.Calculation = bCalc
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description, vbCritical, "ERRORE"
End If
End Sub
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
'---------------------------------------------------------------------------------------
' Procedure : CheckCash
' Author : scossa
' Date : 08/04/2014
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Sub CheckCash()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim cella As Range
Dim cPaym As Collection
Dim vPaym As Variant
Dim aCash As Variant
Dim nMax As Currency
Dim nMin As Currency
Dim nToll As Currency
Dim j As Long
Dim k As Long
Dim nRows As Long
Dim bCalc As XlCalculation
' On Error GoTo CheckCash_Error
With Application
bCalc = .Calculation
.Calculation = xlCalculationManual
End With
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Foglio1")
Set rng = ws.Range("H4:H" & ws.Cells(Rows.Count, 8).End(xlUp).Row)
Set aCash = New Collection
Set cPaym = New Collection
nToll = ws.Range("P1").Value
rng.Offset(, 7).ClearContents
nRows = rng.Rows.Count
ReDim aCash(1 To nRows, 1 To 2)
For k = 1 To nRows
With rng(k, 1)
aCash(k, 1) = .Value
aCash(k, 2) = ""
End With
Next k
For Each cella In rng.Offset(, 8)
With cella
cPaym.Add Array(.Value, .Offset(0, 1).Value)
End With
Next cella
For k = 1 To nRows
j = 0
For Each vPaym In cPaym
j = j + 1
If vPaym(0) = aCash(k, 1) Then
aCash(k, 1) = vPaym(0)
aCash(k, 2) = vPaym(1)
cPaym.Remove j
Exit For
End If
Next
Next k
For k = 1 To nRows
If aCash(k, 2) = "" Then
nMin = aCash(k, 1) - nToll
nMax = aCash(k, 1) + nToll
j = 0
For Each vPaym In cPaym
j = j + 1
If (vPaym(0) >= nMin And vPaym(0) <= nMax) Then
aCash(k, 1) = vPaym(0)
aCash(k, 2) = vPaym(1)
cPaym.Remove j
Exit For
End If
Next
End If
Next k
For j = 1 To nRows
rng.Cells(j, 1).Offset(0, 7) = aCash(j, 2)
Next j
On Error GoTo 0
'Exit Sub
CheckCash_Error:
Set wb = Nothing
Set ws = Nothing
Set rng = Nothing
Set cPaym = Nothing
Set aCash = Nothing
Application.Calculation = bCalc
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description, vbCritical, "ERRORE"
End If
End Sub
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
