Sub APRI_FILE_GARANZIE_3()
Dim sFile As String, S As String, res As String, l As Long, posend As Long, posini As Long
'Memorizza Directory File.txt e Agenzia
Application.CutCopyMode = False
direct = Sheets("menu").Range("D4").Value
AGE = Sheets("MENU").Range("D6").Value
'Identifica percorso e nome file
Director = Application.ActiveWorkbook.Path 'Percorso File
Nome_File = Application.ActiveWorkbook.Name 'Nome File
fpath = ThisWorkbook.Path & ""
Nome_File_txt = "File_ridotto.txt" 'Nome File Txt
'Memorizza nome file da Aprire
Sheets("TAB").Select
Dim NomeFile As String
Nome_File_Originale_txt = Range("E3").Value
RIGA = Range("G2").Value
Nome_File_Originale_txt = Range("E" & RIGA).Value
'Estrai dati e crea nuovo File Ridotto GARANZIE
fpath = ThisWorkbook.Path & ""
sFile = direct & "" & Nome_File_Originale_txt
ofile = fpath & "File_ridotto.txt"
i = FreeFile
l = FileLen(sFile)
res = Space(l)
Open sFile For Binary Access Read As #i
Get #i, , res
Close i
strSearch = Array("NXWEB_RISCHIO")
strEnd = Array("NXWEB_PERSONA")
For IND = 0 To 0
posend = InStr(res, strEnd(IND))
posini = InStr(res, strSearch(IND))
S = S & Mid(res, posini, posend - posini)
Next
i = FreeFile
Open ofile For Output As i
Print #i, S
Close
sFile = fpath & "File_Ridotto.txt"
'Apri File Ridotto
Workbooks.OpenText Filename:=sFile, Origin:= _
xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 2), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), _Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 2), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 2), Array(35, 1), Array(36, 2), Array(37, 1), Array(38, 2), Array(39, 1), Array(40, 2), Array(41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 2), Array(47, 1), Array(48, 1)), TrailingMinusNumbers:=True
FileRidotto = sFile
S = ""
'Assegna Nome al file TXT aperto
Nome_File_txt = Application.ActiveWorkbook.Name 'Nome File Txt
Windows(Nome_File).Activate
Call DATI_GARANZIE_3
------------------------------------------------------------------
End Sub
Sub DATI_GARANZIE_3()
On Error GoTo ERRORE_19
Nome_File = Application.ActiveWorkbook.Name 'Nome File XLS
Nome_File_txt = "File_ridotto.txt" 'Nome File Txt
'Estrai CLASSI BM
Windows(Nome_File_txt).Activate
urR = Range("B4").End(xlDown).Row
urB = Range("B4").End(xlDown).Row
With Range("R4", "R" & urB) 'Incolla formula
.FormulaR1C1 = "=IF(AND(RC16="""",RC17=""""),1,0)"
.Value2 = .Value2
End With
Range("A3:AQ" & urB).Select
Selection.Sort Key1:=Range("R3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
If Range("R3").Value <> 0 Then GoTo NO_CLASSI0: 'Nessuna garanzia doppia da eliminare
Range("R3", "R" & urB).Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
srB = ActiveCell.Address
urR = ActiveCell.Row - 1
Range("P3:Q" & urR).Copy
Windows(Nome_File).Activate
Sheets("CLASSI").Select
Range("B65500").End(xlUp).Offset(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Windows("File_ridotto.txt").Activate
Range("AK3:AK" & urR).Copy
Windows(Nome_File).Activate
Sheets("CLASSI").Select
Range("B65500").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A" & prB, "A" & urB) = Range("A1")
Range("A4", "D" & urB).Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
NO_CLASSI0:
'Elimina Classi doppie
urB = Range("B4").End(xlDown).Row
Range("A4:D" & urB).Select
Selection.Sort Key1:=Range("B4"), Order1:=xlAscending, Key2:=Range("A4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
With Range("F4", "F" & urB) 'Incolla formula
.FormulaR1C1 = "=IF(RC2=R[1]C2,0,1)"
.Value2 = .Value2
End With
Range("A4:F" & urB).Select
Selection.Sort Key1:=Range("F4"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
If Range("F" & urB).Value <> 0 Then GoTo NO_CLASSI1: 'Nessuna garanzia doppia da eliminare
Range("F4", "F" & urB).Select
Selection.Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
srB = ActiveCell.Address
Range(srB, "F" & urB).Select
Selection.EntireRow.Delete
Range("F4:F" & urB).ClearContents
'YY:
urB = Range("B4").End(xlDown).Row
Range("A4:F" & urB).Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
NO_CLASSI1:
Windows(Nome_File_txt).Activate
NO_CLASSI:
'--------------------------------------------------------------------------------------------------------
|