
Range("H1").Select
ActiveCell.FormulaR1C1 = "=NOW()"
INIZIO = ActiveCell.Text
ActiveCell.Value = ""
Columns("B:C").Select
Selection.ClearContents
Range("A65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(0, 10).Select
ActiveCell.FormulaR1C1 = "=ROW()"
RIGA = ActiveCell.Value + 1
ActiveCell.Value = ""
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "NUM"
Range("B1").Select
ActiveCell.FormulaR1C1 = "CF"
Range("C1").Select
ActiveCell.FormulaR1C1 = "COD"
Range("C2").Select
W = 1
For i = 2 To RIGA
Range("A" & i).Select
ActiveCell.Value = W
Let W = W + 1
Next i
For i = 2 To RIGA
lunghezza = Len(Range("B" & i))
If lunghezza = 16 Then
ESTRATTO = Mid(Range("B" & i), 12, 4)
Range("C" & i).Value = ESTRATTO
End If
Next i
Range("A1").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Columns("C:C").Select
Selection.ClearContents
Range("C1").Select
ActiveCell.FormulaR1C1 = "COD"
For i = 2 To RIGA
For H = 1 To 8424
lunghezza = Len(Range("B" & i))
If lunghezza = 16 Then
ESTRATTO = Mid(Range("B" & i), 12, 4)
If ESTRATTO = Foglio4.Range("A" & H).Value Then
Range("C" & i).Value = Foglio4.Range("B" & H).Value
Range("D" & i).Value = Foglio4.Range("C" & H).Value
GoTo 10
End If
End If
Next H
10 Next i
Range("A1").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "=NOW()"
FINE = ActiveCell.Text
ActiveCell.Value = ""
Application.ScreenUpdating = True
MsgBox "INIZIO CALCOLO ORE " & INIZIO & " FINE CALCOLO ORE " & FINE
Range("A1").Select
|
Sub Aggiungi_Loc_a_CF()
Dim L1 As Long, L2 As Long, L3 As Long, L4 As Long
Dim S1 As String, S2 As String
Dim Rng1 As Excel.Range
Dim Rng2 As Excel.Range
Dim arr1() As Variant
Dim arr2() As Variant
Dim arrR() As Variant
Set Rng1 = [foglio1!a1] '< |
If Rng2.Count > 1 Then Exit Sub |
Sub Aggiungi_Loc_a_CF()
Dim L1 As Long, L2 As Long, L3 As Long, L4 As Long
Dim S1 As String, S2 As String
Dim Rng1 As Excel.Range
Dim Rng2 As Excel.Range
Dim arr1() As Variant
Dim arr2() As Variant
Dim arrR() As Variant
Set Rng1 = [foglio1!a1] 'prima cella con CF
If Rng1.Count > 1 Then Exit Sub
Set Rng2 = [foglio2!a1] 'prima cella con Codice città
If Rng2.Count > 1 Then Exit Sub
L1 = UltimaRiga(, Rng1.EntireColumn)
L2 = UltimaRiga(, Rng2.EntireColumn)
Set Rng1 = Rng1.Resize(L1 - Rng1.Row + 1)
Set Rng2 = Rng2.Resize(L2 - Rng2.Row + 1, 3)
arr1 = Rng1.Value
arr2 = Rng2.Value
L2 = UBound(arr1, 1)
L4 = UBound(arr2, 1)
ReDim arrR(1 To UBound(arr1), 1 To 3)
For L1 = 1 To L2
S1 = arr1(L1, 1)
S2 = Mid(S1, 13, 3)
arrR(L1, 1) = S1
For L3 = 1 To L4
If S2 = arr2(L3, 1) Then
arrR(L1, 2) = arr2(L3, 2)
arrR(L1, 3) = arr2(L3, 3)
Exit For
End If
Next L3
Next L1
Set Rng2 = ThisWorkbook.Worksheets.Add().Range("A1")
Set Rng2 = Rng2.Resize(L1 - 1, 3)
Rng2.Value = arrR
End Sub
Function UltimaRiga(Optional sh As Worksheet, _
Optional Rng As Range) As Long
'By Norman Jones modificata restituisce
'l'ultima riga valorizzata
'restituisce 0 se il foglio è pulito
'passando Sh verrà ignorato Rng
'passando Rng verrà ignorato Sh
'non passando argomenti verrà ricercata
'l'ultima riga valorizzata del foglio
'attivo
'utilizzata come UDF è consigliabile
'passare Rng
If sh Is Nothing Then
If Rng Is Nothing Then
Set Rng = [a1].Parent.UsedRange
End If
Else
Set Rng = sh.UsedRange
End If
On Error Resume Next
UltimaRiga = Rng.Find(What:="*", _
After:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
|
S2 = Mid(S1, 12, 4) |
