Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 218.70 KB | None | 0 0
  1. Dim conn As New ADODB.Connection
  2. Dim connString As String
  3. Dim rs As New ADODB.Recordset
  4. Dim conn2 As New ADODB.Connection
  5. Dim connString2 As String
  6. Dim rs2 As New ADODB.Recordset
  7.  
  8. Dim ciclo() As String
  9. Dim ciclo_pop() As String
  10. Dim ciclo_placa() As String
  11. Dim mux() As String
  12. Public Type modens
  13.     nome As String
  14.     cor_fonte As String
  15.     linha As Integer
  16.     novo_nome As String
  17. End Type
  18. Public Type tipo_modem
  19.     nome As String
  20.     seq As Integer
  21. End Type
  22. Public Type placas
  23.     nome As String
  24.     seq As Integer
  25. End Type
  26. Public Type portas
  27.     nome As String
  28.     seq As Integer
  29. End Type
  30.  
  31. Public Type canalizados
  32.  
  33.     facilidade As String
  34.     circuito As String
  35.     vc As String
  36.     aba As String
  37.     arquivo As String
  38.     subend As String
  39.    
  40. End Type
  41.  
  42. Public Type array_canal
  43.  
  44.     n64 As String
  45.     ts As String
  46.     facilidade As String
  47.    
  48. End Type
  49.  
  50. Public Type ultima_milha
  51.  
  52.     mux As String
  53.     circuito As String
  54.     aba As String
  55.     arquivo As String
  56.     subend As String
  57.     end2 As String
  58.     porta_mux As String
  59.     tipo_mux As String
  60.     slot_mux As String
  61.     status_circ As String
  62.     cliente_circ As String
  63.     placa As String
  64.    
  65. End Type
  66.  
  67.  
  68.  
  69.  
  70. Private Sub ConnectDB()
  71.     'CONECTA NO BANCO DA MYSQL - necessita do driver ODBC
  72.    Set conexao = New ADODB.Connection
  73.     conexao.Open "DRIVER={MySQL ODBC 5.2 ANSI Driver};" & _
  74.                  "SERVER=mysql.infovias.unix.corp;" & _
  75.                 "DATABASE=sicop;" & _
  76.                  "USER=sicop;" & _
  77.                  "PASSWORD=sicop;" & _
  78.                  "Option=3"
  79.  
  80.  
  81. End Sub
  82.  
  83. Public Sub main()
  84.  
  85. Application.ScreenUpdating = False
  86.  
  87.  
  88. Dim FSO As New FileSystemObject
  89. Dim array_ultimamilha() As Variant
  90. ReDim Preserve array_ultimamilha(0)
  91.  
  92. 'obter pasta temporaria
  93. profile_folder = GetSpecialFolderPaths()
  94.  
  95. arquivos_RMBH = Array("Controle_RMBHE_1.xlsx", "Controle_RMBHE_2.xlsx", "Controle_RMBHE_3.xlsx", "Controle_RMBHE_4.xlsx", "Controle_RMBHE_5.xlsx", "Controle_RMBHE_6.xlsx", "Controle_RMBHE_7.xlsx", "Controle_RMBHE_8.xlsx", "Vesper.xlsx")
  96. arquivos_interior = Array("Pops_e_Sites_Interior_Leste.xlsx", "Pops_e_Sites_Interior_Oeste.xlsx", "Pops_e_Sites_Interior_Norte.xlsx", "Pops_e_Sites_Interior_Sul.xlsx", "Pops_e_Sites_Interior_Sudeste.xlsx", "Pops_e_Sites_Outros_Estados.xlsx")
  97.  
  98. 'arquivos_RMBH = Array("Controle_RMBHE_2.xlsx")
  99.  
  100. check_profile_folder = profile_folder & "\SICOP"
  101.  
  102. If FileFolderExists((check_profile_folder)) = True Then
  103.  
  104.     Clear_All_Files_And_SubFolders_In_Folder (check_profile_folder)
  105.  
  106. End If
  107.  
  108. destino_folder = profile_folder & "\SICOP\"
  109.  
  110. If FileFolderExists((destino_folder)) = False Then
  111.  
  112.     create_folder (destino_folder)
  113.  
  114. End If
  115.  
  116.  
  117. 'copiar arquivos do controle de facilidades
  118. destino_folder = profile_folder & "\SICOP\Facilidades\"
  119. create_folder (destino_folder)
  120. destino_folder = profile_folder & "\SICOP\Facilidades\Controle\"
  121. create_folder (destino_folder)
  122.  
  123. For i = 0 To UBound(arquivos_RMBH)
  124.  
  125.     origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\" & arquivos_RMBH(i)
  126.     retorno_copy = Copy_One_File((origem_folder), (destino_folder))
  127.  
  128. Next
  129.  
  130. For i = 0 To UBound(arquivos_interior)
  131.  
  132.     origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\" & arquivos_interior(i)
  133.     retorno_copy = Copy_One_File((origem_folder), (destino_folder))
  134.  
  135. Next
  136.  
  137. destino_folder = profile_folder & "\SICOP\Comercial\"
  138. create_folder (destino_folder)
  139. origem_folder = "\\file_server\Viabilidades\Banco_OS\BD_ATIVACOES.mdb"
  140. retorno_copy = Copy_One_File((origem_folder), (destino_folder))
  141.  
  142.  
  143.  
  144. destino_folder = profile_folder & "\SICOP\Auxiliar\"
  145. create_folder (destino_folder)
  146. origem_folder = "\\fileserver\publico\SICOP\Script_Macro\hierarquias.xlsx"
  147. retorno_copy = Copy_One_File((origem_folder), (destino_folder))
  148.  
  149. destino_folder = profile_folder & "\SICOP\Auxiliar\"
  150. origem_folder = "\\fileserver\publico\SICOP\Script_Macro\operadoras.xlsx"
  151. retorno_copy = Copy_One_File((origem_folder), (destino_folder))
  152.  
  153. destino_folder = profile_folder & "\SICOP\Facilidades\Operadoras\"
  154. create_folder (destino_folder)
  155.  
  156. destino_folder = profile_folder & "\SICOP\Facilidades\Operadoras\RMBH\"
  157. create_folder (destino_folder)
  158. origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\Operadoras"
  159. retorno_copy = Copy_Folder((origem_folder), (destino_folder))
  160.  
  161. destino_folder = profile_folder & "\SICOP\Facilidades\Operadoras\Interior\"
  162. create_folder (destino_folder)
  163. origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\Operadoras_e_canalizados"
  164. retorno_copy = Copy_Folder((origem_folder), (destino_folder))
  165.  
  166. destino_folder = profile_folder & "\SICOP\Facilidades\Canalizados\"
  167. create_folder (destino_folder)
  168.  
  169. destino_folder = profile_folder & "\SICOP\Facilidades\Canalizados\RMBH\"
  170. create_folder (destino_folder)
  171. origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\Canalizados\Canalizados VC-12"
  172. retorno_copy = Copy_Folder((origem_folder), (destino_folder))
  173.  
  174. destino_folder = profile_folder & "\SICOP\Facilidades\Canalizados\Interior\"
  175. create_folder (destino_folder)
  176. origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\Canalizados"
  177. retorno_copy = Copy_Folder((origem_folder), (destino_folder))
  178.  
  179. For i = 0 To UBound(arquivos_RMBH)
  180.     valor = profile_folder & "\SICOP\Facilidades\Controle\" + arquivos_RMBH(i)
  181.     'valor = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\" + arquivos_RMBH(i)
  182.    array_ultimamilha(UBound(array_ultimamilha)) = valor
  183.     ReDim Preserve array_ultimamilha(UBound(array_ultimamilha) + 1)
  184.  
  185. Next
  186.  
  187. For i = 0 To UBound(arquivos_interior)
  188.     'valor = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\" + arquivos_interior(i)
  189.    valor = profile_folder & "\SICOP\Facilidades\Controle\" + arquivos_interior(i)
  190.     array_ultimamilha(UBound(array_ultimamilha)) = valor
  191.     ReDim Preserve array_ultimamilha(UBound(array_ultimamilha) + 1)
  192.  
  193. Next
  194.  
  195. ReDim Preserve array_ultimamilha(UBound(array_ultimamilha) - 1)
  196.  
  197. principal = ActiveWorkbook.Name
  198. Workbooks.Add
  199. ActiveWorkbook.Activate
  200. tabelao = ActiveWorkbook.Name
  201. Windows(tabelao).Activate
  202. ActiveWindow.Zoom = 75
  203.  
  204. 'planilha_UM = ultimamilha(array_ultimamilha(), (tabelao))
  205.  
  206. path_PM = profile_folder & "\SICOP\Facilidades\Operadoras\"
  207.  
  208. 'planilha_PM = primeiramilha((path_PM))
  209.  
  210. 'planilha_canalizados = canalizados_pla(array_ultimamilha())
  211.  
  212. path_comercial = profile_folder & "\SICOP\Comercial\BD_ATIVACOES.mdb"
  213.  
  214. planilha_comercial = compara_eng_com(array_ultimamilha, path_comercial, path_PM)
  215.  
  216.  
  217. 'Windows(planilha_UM).Activate
  218.  
  219. 'Sheets("Plan1").Name = "Ultima_Milha"
  220.  
  221. 'Sheets("Ultima_Milha").Move After:=Workbooks(tabelao).Sheets(1)
  222.  
  223. 'Windows(planilha_PM).Activate
  224.  
  225. 'Sheets("Plan1").Name = "Primeira_Milha"
  226.  
  227. 'Sheets("Primeira_Milha").Move After:=Workbooks(tabelao).Sheets(1)
  228.  
  229. 'Windows(planilha_canalizados).Activate
  230.  
  231. 'Sheets("Plan1").Name = "Canalizados"
  232. '
  233. 'Sheets("Canalizados").Move After:=Workbooks(tabelao).Sheets(1)
  234. '
  235. 'Windows(planilha_comercial).Activate
  236. '
  237. 'Sheets("Plan1").Name = "Comercial"
  238. '
  239. 'Sheets("Comercial").Move After:=Workbooks(tabelao).Sheets(1)
  240. '
  241. 'Windows(tabelao).Activate
  242. '
  243. 'Sheets("Plan1").Name = "Todas_Facilidades"
  244. '
  245. Application.ScreenUpdating = True
  246. '
  247. End Sub
  248.  
  249.  
  250. Public Function compara_eng_com(Filename As Variant, path_comercial As Variant, path_PM As Variant) As String
  251.  
  252. Dim sheet  As Worksheet
  253.   Dim celula, celula1 As Range
  254.   Dim LastRow As Long
  255.  
  256.    Dim Filter As String
  257.    Dim FilterIndex As Integer
  258.    'Dim filename As Variant
  259.   Dim remove As String
  260.    Dim path As String
  261.    
  262.    'Dim canalizados() As canalizado
  263.   'Dim array_temp() As array_canal
  264.   'ReDim Preserve canalizados(0)
  265.  ' ReDim Preserve array_temp(0)
  266.   Dim ultima_milha() As ultima_milha
  267.    Dim comercial() As String
  268.    ReDim Preserve ultima_milha(0)
  269.    ReDim Preserve comercial(0)
  270.    
  271. connString = "DSN=sicop_prod2;Uid=sicop_prod2;Pwd=sicop_prod2"
  272.  
  273. If conn.State = adStateOpen Then
  274.     conn.Close
  275. End If
  276.  
  277. conn.Open connString
  278.  
  279. rs.LockType = adLockBatchOptimistic
  280. rs.CursorLocation = adUseClient
  281. rs2.LockType = adLockBatchOptimistic
  282. rs2.CursorLocation = adUseClient
  283.    
  284.  'Não atualizar a tela durante o script.
  285.  'Application.ScreenUpdating = False
  286.  
  287. ' File filters - Filtro dos tipos de arquivos que aparecem na caixa de dialogo de escolha do arquivo.
  288. 'Filter = "Excel Files (*.xls),*.xls," & _
  289.         '"Text Files (*.txt),*.txt," & _
  290.         '"All Files (*.*),*.*"
  291. '   Default filter to *.*
  292.    'FilterIndex = 3
  293. ' Set Dialog Caption
  294. 'TITULO DA CAIXA
  295. 'Title = "Escolha o arquivo de circuitos "
  296. ' Select Start Drive & Path - Caminho da caixa de dialogo.
  297. 'ChDrive ("C")
  298. 'ChDir ("C:\")
  299.  
  300. 'ABRE CADA ARQUIVO SELECIONADO DA CAIXA DE DIALOGO
  301. 'With Application
  302.    'Set File Name Array to selected Files (allow multiple)
  303.    'Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  304.    'Reset Start Drive/Path
  305.    'ChDrive (Left(.DefaultFilePath, 1))
  306.    'ChDir (.DefaultFilePath)
  307. 'End With
  308. 'Exit on Cancel
  309.  
  310. ' File filters
  311. 'Filter = "Excel Files (*.xls),*.xls," & _
  312. '         "Text Files (*.txt),*.txt," & _
  313. '         "All Files (*.*),*.*"
  314. ''   Default filter to *.*
  315. 'FilterIndex = 3
  316. '' Set Dialog Caption
  317. 'Title = "Escolha o arquivo de circuitos da Engenharia"
  318. '' Select Start Drive & Path
  319. 'ChDrive ("C")
  320. 'ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia")
  321. 'With Application
  322. '    ' Set File Name Array to selected Files (allow multiple)
  323. '    Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  324. '    ' Reset Start Drive/Path
  325. '    ChDrive (Left(.DefaultFilePath, 1))
  326. '    ChDir (.DefaultFilePath)
  327. 'End With
  328. '' Exit on Cancel
  329. '
  330. 'If Not IsArray(Filename) Then
  331. '    MsgBox "Nenhum arquivo selecionado."
  332. '    Exit Function
  333. 'End If
  334.  
  335. principal = ActiveWorkbook.Name
  336. '    Workbooks.Add
  337. '    ActiveWorkbook.Activate
  338. '    erros = ActiveWorkbook.Name
  339.  
  340. ' Open Files
  341. For sasa = LBound(Filename) To UBound(Filename)    ' FOR abre arquivos
  342.    msg = msg & Filename(sasa) & vbCrLf    ' This can be removed
  343.    Workbooks.Open Filename(sasa), False
  344.  
  345.     arquivo = ActiveWorkbook.Name
  346.    
  347.        
  348.     If arquivo Like "*Interior*" Then
  349.  
  350.         caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
  351.  
  352.     Else
  353.  
  354.         caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
  355.  
  356.     End If
  357.  
  358.     end2 = (caminhoarquivo & "\" & arquivo)
  359.    
  360.     Windows(arquivo).Activate
  361.    
  362.     For Each sheet In ActiveWorkbook.Worksheets
  363.      
  364.         If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  365.  
  366.                 sheet.Select
  367.                
  368.                 aba = sheet.Name
  369.                
  370.                 If WorksheetFunction.CountA(Cells) > 0 Then
  371.                     'Search for any entry, by searching backwards by Rows.
  372.                    LastRow = Cells.Find(What:="*", After:=[A1], _
  373.                                          SearchOrder:=xlByRows, _
  374.                                          SearchDirection:=xlPrevious).Row
  375.  
  376.                 End If
  377.                
  378.                 For Each celula In Range("C3:C" & LastRow)
  379.                    
  380.                    
  381.                
  382.                     linha = celula.Row
  383.                    
  384.                    
  385.                                        
  386.                     If Range("C" & linha).Interior.ColorIndex = 1 Then
  387.                    
  388.                         mux_milha = Range("C" & linha).Value
  389.                    
  390.                     End If
  391.                    
  392.                     If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
  393.                    
  394.                         velocidade = Range("D" & linha).Value
  395.                        
  396.                         status_circ = Range("B" & linha).Value
  397.                        
  398.                         cliente_circ = Range("G" & linha).Value
  399.                        
  400.                         If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
  401.                             placa = Range("K" & linha).Value
  402.                         End If 'If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
  403.                        
  404.                         If Not IsEmpty(Range("L" & linha)) Or Range("L" & linha).Value <> "" Then
  405.                             slot_mux = Range("L" & linha).Value
  406.                         End If 'If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
  407.                        
  408.                         If Not IsEmpty(Range("M" & linha)) Or Range("M" & linha).Value <> "" Then
  409.                             porta = Range("M" & linha).Value
  410.                         End If 'If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
  411.                        
  412.                        
  413.                        ' canal = checa_canalizado(velocidade)
  414.                        
  415.                        ' If canal = 1 Then
  416.                        
  417.                             If InStr(1, Range("C" & linha).Value, "  ") <> 0 Then
  418.                            
  419.                                 Range("C" & linha).Value = Replace(Range("C" & linha).Value, "  ", " ")
  420.                                
  421.                             ElseIf InStr(1, Range("C" & linha).Value, "   ") <> 0 Then
  422.                            
  423.                                 Range("C" & linha).Value = Replace(Range("C" & linha).Value, "   ", " ")
  424.                            
  425.                             End If
  426.                        
  427.                             ultima_milha(UBound(ultima_milha)).circuito = UCase(Trim(Range("C" & linha).Value))
  428.                             ultima_milha(UBound(ultima_milha)).mux = mux_milha
  429.                             ultima_milha(UBound(ultima_milha)).arquivo = arquivo
  430.                             ultima_milha(UBound(ultima_milha)).aba = aba
  431.                            ' ultima_milha(UBound(ultima_milha)).subend = ("'" & aba & "'!" & Removedolars(Range("C" & linha).Address))
  432.                            ultima_milha(UBound(ultima_milha)).end2 = end2
  433.                             ultima_milha(UBound(ultima_milha)).status_circ = status_circ
  434.                             ultima_milha(UBound(ultima_milha)).cliente_circ = cliente_circ
  435.                             ultima_milha(UBound(ultima_milha)).slot_mux = slot_mux
  436.                             ultima_milha(UBound(ultima_milha)).placa = placa
  437.                             ultima_milha(UBound(ultima_milha)).porta_mux = porta
  438.                                                        
  439.                             ReDim Preserve ultima_milha(UBound(ultima_milha) + 1)
  440.                        
  441.                        
  442.                       '  End If ' If canal = 1 Then
  443.                    
  444.                    
  445.                     End If 'If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
  446.                
  447.                
  448.                 Next
  449.                
  450.                
  451.                
  452.      
  453.         End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  454.    Next 'For Each sheet In ActiveWorkbook.Worksheets
  455.    
  456.    
  457.     Windows(arquivo).Close False
  458. Next
  459.  
  460.  
  461. '
  462. '
  463. '' File filters
  464. 'Filter = "Excel Files (*.xls),*.xls," & _
  465. '         "Text Files (*.txt),*.txt," & _
  466. '         "All Files (*.*),*.*"
  467. ''   Default filter to *.*
  468. 'FilterIndex = 3
  469. '' Set Dialog Caption
  470. 'Title = "Escolha o arquivo de circuitos do Comercial"
  471. '' Select Start Drive & Path
  472. 'ChDrive ("C")
  473. 'ChDir ("C:\")
  474. 'With Application
  475. '    ' Set File Name Array to selected Files (allow multiple)
  476. '    filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  477. '    ' Reset Start Drive/Path
  478. '    ChDrive (Left(.DefaultFilePath, 1))
  479. '    ChDir (.DefaultFilePath)
  480. 'End With
  481. '' Exit on Cancel
  482. '
  483. 'If Not IsArray(filename) Then
  484. '    MsgBox "Nenhum arquivo selecionado."
  485. '    Exit Function
  486. 'End If
  487.  
  488. Windows(principal).Activate
  489.  
  490. linha = 1
  491. 'rs.Close
  492.  
  493. For i = 0 To UBound(ultima_milha)
  494.  
  495.     id_circuito = 0
  496.     id_er = 0
  497.     id_slot = 0
  498.     id_porta = 0
  499.    
  500.     select_circuito = "select id_circuito from circuito where upper(dsc_designacao) = upper('" & ultima_milha(i).circuito & "')"
  501.     rs.Open select_circuito, conn
  502.    
  503.     If rs.BOF = False Then
  504.    
  505.         id_circuito = rs!id_circuito
  506.        
  507.      Range("A" & linha).Value = ultima_milha(i).circuito
  508.      Range("B" & linha).Value = id_circuito
  509.    
  510.     Else
  511.    
  512.      Range("A" & linha).Value = ultima_milha(i).circuito
  513.      Range("B" & linha).Value = "NE"
  514.    
  515.     End If
  516.    
  517.     rs.Close
  518.    
  519.     If id_circuito <> 0 Then
  520.    
  521.        
  522.         select_er = "select id_planejavel from elemento_rede where upper(sgl_elemento) = '" & UCase(ultima_milha(i).mux) & "'"
  523.         rs.Open select_er, conn
  524.        
  525.         If rs.BOF = False Then
  526.        
  527.          id_er = rs!id_planejavel
  528.            
  529.          Range("C" & linha).Value = ultima_milha(i).mux
  530.          Range("D" & linha).Value = id_er
  531.        
  532.         Else
  533.        
  534.          Range("C" & linha).Value = ultima_milha(i).mux
  535.          Range("D" & linha).Value = "NE"
  536.        
  537.         End If
  538.        
  539.         rs.Close
  540.        
  541.         If id_er <> 0 Then
  542.        
  543.                 slot_teste1 = ultima_milha(i).mux & "." & ultima_milha(i).slot_mux
  544.                                
  545.                 slot_teste1 = UCase(slot_teste1)
  546.                
  547.                 select_slot = "select id_planejavel from slot_er where upper(sgl_elemento) = '" & slot_teste1 & "'"
  548.                 rs.Open select_slot, conn
  549.                
  550.                 If rs.BOF = False Then
  551.                
  552.                  id_slot = rs!id_planejavel
  553.                    
  554.                  Range("E" & linha).Value = ultima_milha(i).slot_mux
  555.                  Range("F" & linha).Value = id_slot
  556.                
  557.                 Else
  558.                
  559.                  Range("E" & linha).Value = ultima_milha(i).slot_mux
  560.                  Range("F" & linha).Value = "NE"
  561.                
  562.                 End If
  563.                
  564.                 rs.Close
  565.                
  566.                 If id_slot = 0 Then
  567.                
  568.                     If Len(ultima_milha(i).slot_mux) <= 3 Then
  569.                      If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
  570.                      
  571.                         slot_teste2 = ultima_milha(i).mux & "." & Mid(ultima_milha(i).slot_mux, InStr(1, UCase(ultima_milha(i).slot_mux), "S") + 1)
  572.                                        
  573.                         slot_teste2 = UCase(slot_teste2)
  574.                        
  575.                         select_slot = "select id_planejavel from slot_er where upper(sgl_elemento) = '" & slot_teste2 & "'"
  576.                         rs.Open select_slot, conn
  577.                        
  578.                         If rs.BOF = False Then
  579.                        
  580.                          id_slot = rs!id_planejavel
  581.                            
  582.                          Range("E" & linha).Value = ultima_milha(i).slot_mux
  583.                          Range("F" & linha).Value = id_slot
  584.                        
  585.                         Else
  586.                        
  587.                          Range("E" & linha).Value = ultima_milha(i).slot_mux
  588.                          Range("F" & linha).Value = "NE"
  589.                        
  590.                         End If 'If rs.BOF = False Then
  591.                        
  592.                         rs.Close
  593.                    
  594.                      End If 'If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
  595.                    End If ' If Len(ultima_milha(i).slot_mux) <= 3 Then
  596.                
  597.                 End If
  598.                
  599.                 If id_slot = 0 Then
  600.                
  601.                     select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & ultima_milha(i).porta_mux & "'"
  602.                     rs.Open select_porta, conn
  603.                    
  604.                     If rs.BOF = False Then
  605.                    
  606.                      id_porta = rs!id_porta_er
  607.                        
  608.                      Range("G" & linha).Value = ultima_milha(i).porta_mux
  609.                      Range("H" & linha).Value = id_porta
  610.                    
  611.                     Else
  612.                    
  613.                      Range("G" & linha).Value = ultima_milha(i).porta_mux
  614.                      Range("H" & linha).Value = "NE"
  615.                    
  616.                     End If
  617.                    
  618.                     rs.Close
  619.                    
  620.                     If id_porta = 0 Then
  621.                    
  622.                         If Len(ultima_milha(i).porta_mux) <= 3 Then
  623.                          If InStr(1, UCase(ultima_milha(i).porta_mux), "P") <> 0 Then
  624.                          
  625.                             porta_teste = Mid(1, InStr(1, UCase(ultima_milha(i).porta_mux), "P") + 1)
  626.                                            
  627.                             porta_teste = UCase(porta_teste)
  628.                            
  629.                             select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & porta_teste & "'"
  630.                             rs.Open select_porta, conn
  631.                            
  632.                             If rs.BOF = False Then
  633.                            
  634.                              id_porta = rs!id_porta_er
  635.                                
  636.                              Range("G" & linha).Value = ultima_milha(i).porta_mux
  637.                              Range("H" & linha).Value = id_porta
  638.                            
  639.                             Else
  640.                            
  641.                              Range("G" & linha).Value = ultima_milha(i).porta_mux
  642.                              Range("H" & linha).Value = "NE"
  643.                            
  644.                             End If
  645.                            
  646.                             rs.Close
  647.                        
  648.                          End If 'If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
  649.                        End If ' If Len(ultima_milha(i).slot_mux) <= 3 Then
  650.                    
  651.                     End If
  652.                    
  653.                 Else
  654.                
  655.                  select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_slot = " & id_slot & " and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & ultima_milha(i).porta_mux & "'"
  656.                     rs.Open select_porta, conn
  657.                    
  658.                     If rs.BOF = False Then
  659.                    
  660.                      id_porta = rs!id_porta_er
  661.                        
  662.                      Range("G" & linha).Value = ultima_milha(i).porta_mux
  663.                      Range("H" & linha).Value = id_porta
  664.                    
  665.                     Else
  666.                    
  667.                      Range("G" & linha).Value = ultima_milha(i).porta_mux
  668.                      Range("H" & linha).Value = "NE"
  669.                    
  670.                     End If
  671.                    
  672.                     rs.Close
  673.                    
  674.                     If id_porta = 0 Then
  675.                    
  676.                         If Len(ultima_milha(i).porta_mux) <= 3 Then
  677.                          If InStr(1, UCase(ultima_milha(i).porta_mux), "P") <> 0 Then
  678.                          
  679.                             porta_teste = Mid(ultima_milha(i).porta_mux, InStr(1, UCase(ultima_milha(i).porta_mux), "P") + 1)
  680.                                            
  681.                             porta_teste = UCase(porta_teste)
  682.                            
  683.                             select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_slot = " & id_slot & " and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & porta_teste & "'"
  684.                             rs.Open select_porta, conn
  685.                            
  686.                             If rs.BOF = False Then
  687.                            
  688.                              id_porta = rs!id_porta_er
  689.                                
  690.                              Range("G" & linha).Value = ultima_milha(i).porta_mux
  691.                              Range("H" & linha).Value = id_porta
  692.                            
  693.                             Else
  694.                            
  695.                              Range("G" & linha).Value = ultima_milha(i).porta_mux
  696.                              Range("H" & linha).Value = "NE"
  697.                            
  698.                             End If
  699.                            
  700.                             rs.Close
  701.                        
  702.                          End If 'If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
  703.                        End If ' If Len(ultima_milha(i).slot_mux) <= 3 Then
  704.                    
  705.                     End If
  706.                
  707.                
  708.                
  709.                 End If ' if id_slot = 0 then
  710.                
  711.                 If id_porta <> 0 Then
  712.                
  713.                     select_porta_circ = "select * from circuito where id_porta_origem = " & id_porta
  714.                     rs.Open select_porta_circ, conn
  715.                    
  716.                     If rs.BOF = False Then
  717.                    
  718.                         Range("I" & linha).Value = "Porta Origem Encontrada"
  719.                    
  720.                     Else
  721.                    
  722.                         rs.Close
  723.                        
  724.                         select_porta_circ = "select * from circuito where id_porta_destino = " & id_porta
  725.                         rs.Open select_porta_circ, conn
  726.                        
  727.                         If rs.BOF = False Then
  728.                            
  729.                             Range("I" & linha).Value = "Porta Destino Encontrada"
  730.                        
  731.                         Else
  732.                            
  733.                             Range("I" & linha).Value = "Circuito sem portas no SICOP"
  734.                            
  735.                         End If
  736.                        
  737.                    
  738.                         rs.Close
  739.                     End If 'If rs.BOF = False Then
  740.                
  741.                
  742.  
  743.                 End If 'If id_porta <> 0 Then
  744.            
  745.            
  746.        
  747.         End If 'If id_er <> 0 Then
  748.        
  749.      End If 'If id_circuito <> 0 Then
  750.        
  751.    
  752. linha = linha + 1
  753. Next
  754.  
  755.  
  756.  
  757.  
  758. compara_eng_com = nova
  759.  
  760. End Function
  761.  
  762. Public Function arruma(ByVal texto As String) As String
  763.  
  764.     arruma = RemoveSpaces(UCase(texto))
  765.  
  766. End Function
  767.  
  768. Public Function RemoveSpaces(ByVal strInput As String)
  769. ' Removes all spaces from a string of text
  770. Test:
  771.    If InStr(strInput, " ") = 0 Then
  772.       RemoveSpaces = strInput
  773.    Else
  774.       strInput = Left(strInput, InStr(strInput, " ") - 1) _
  775.       & Right(strInput, Len(strInput) - InStr(strInput, " "))
  776.       GoTo Test
  777.    End If
  778. End Function
  779.  
  780. Public Function erro(ByVal arq_erro As String, ByVal origem As String, ByVal endereco As String, ByVal subend As String, ByVal valor As String, ByVal dsc_erro As String) As Integer
  781.  
  782. If valor = "" Then
  783.    
  784.     valor = "Erro"
  785.  
  786. End If
  787.  
  788. Windows(arq_erro).Activate
  789.  
  790.     If WorksheetFunction.CountA(Cells) > 0 Then
  791.         'Search for any entry, by searching backwards by Rows.
  792.        LastRow = Cells.Find(What:="*", After:=[A1], _
  793.                                SearchOrder:=xlByRows, _
  794.                                SearchDirection:=xlPrevious).Row
  795.     End If
  796.    
  797.     Range("A" & LastRow + 1).Select
  798.     If endereco <> "" And subend <> "" And valor <> "" Then
  799.    
  800.         ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=endereco, SubAddress:=subend, TextToDisplay:=valor
  801.        
  802.     Else
  803.    
  804.         Range("A" & LastRow + 1).Value = "Erro"
  805.        
  806.     End If
  807.    
  808.     Range("B" & LastRow + 1).Value = dsc_erro
  809.  
  810.  
  811. Windows(origem).Activate
  812.  
  813.  
  814. erro = 0
  815.  
  816. End Function
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824. Public Function create_folder(ByRef MyPath As String)
  825.  
  826. Dim FSO As New FileSystemObject
  827.  
  828. FSO.CreateFolder MyPath
  829.  
  830. End Function
  831.  
  832. Public Function FileFolderExists(ByRef strFullPath As String) As Boolean
  833. 'Author       : Ken Puls (www.excelguru.ca)
  834. 'Macro Purpose: Check if a file or folder exists
  835.    On Error GoTo EarlyExit
  836.     If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
  837.    
  838. EarlyExit:
  839.     On Error GoTo 0
  840. End Function
  841.  
  842. Public Function Clear_All_Files_And_SubFolders_In_Folder(ByRef MyPath As String)
  843. 'Delete all files and subfolders
  844. 'Be sure that no file is open in the folder
  845.    Dim FSO As Object
  846.     'Dim MyPath As String
  847.    Set FSO = CreateObject("scripting.filesystemobject")
  848.     'MyPath = "C:\Users\a\Test"  '<< Change
  849.    If Right(MyPath, 1) = "\" Then
  850.         MyPath = Left(MyPath, Len(MyPath) - 1)
  851.     End If
  852.     If FSO.FolderExists(MyPath) = False Then
  853.         MsgBox MyPath & " doesn't exist"
  854.         Exit Function
  855.     End If
  856.     On Error Resume Next
  857.     'Delete files
  858.    FSO.DeleteFile MyPath & "\*.*", True
  859.     'Delete subfolders
  860.    FSO.DeleteFolder MyPath & "\*.*", True
  861.     On Error GoTo 0
  862.    
  863.    
  864. End Function
  865.  
  866. Public Function GetSpecialFolderPaths()
  867.     Dim WSHShell        As Object
  868.     Dim strPath         As String
  869.     Dim strFolderName   As String
  870.     Dim intLoop         As Integer
  871.  
  872.     Set WSHShell = CreateObject("Wscript.Shell")
  873.  
  874.     For intLoop = 0 To WSHShell.SpecialFolders.Count - 1
  875.         strPath = WSHShell.SpecialFolders(intLoop)
  876.         strFolderName = Mid(strPath, InStrRev(strPath, Application.PathSeparator) + 1, 9999)
  877.        
  878.         If strFolderName = "Roaming" Then
  879.        
  880.             GetSpecialFolderPaths = strPath
  881.             Exit Function
  882.        
  883.         End If
  884.      
  885.     Next intLoop
  886.  
  887.     Set WSHShell = Nothing
  888. End Function
  889.  
  890. Public Function Copy_Folder(ByRef FromPath As String, ByRef ToPath As String) As String
  891.     Dim FSO As Object
  892.     'Dim FromPath As String
  893.    'Dim ToPath As String
  894.  
  895.    ' ToPath = ToPath & Format(Now, "yyyy-mm-dd h-mm-ss")
  896.  
  897.     If Right(FromPath, 1) = "\" Then
  898.         FromPath = Left(FromPath, Len(FromPath) - 1)
  899.     End If
  900.  
  901.     If Right(ToPath, 1) = "\" Then
  902.         ToPath = Left(ToPath, Len(ToPath) - 1)
  903.     End If
  904.     Set FSO = CreateObject("scripting.filesystemobject")
  905.  
  906.  
  907.     If FSO.FolderExists(FromPath) = False Then
  908.        
  909.         Exit Function
  910.     End If
  911.  
  912.     FSO.CopyFolder Source:=FromPath, Destination:=ToPath
  913.    
  914.     'Copy_Folder  FromPath
  915.  
  916. End Function
  917. Public Function UsedRange_Example_Column()
  918.     Dim LastColumn As Long
  919.     With ActiveSheet.UsedRange
  920.         LastColumn = .Columns(.Columns.Count).Column
  921.     End With
  922.     UsedRange_Example_Column = LastColumn
  923. End Function
  924.  
  925.  
  926. Public Function Copy_One_File(ByRef arq_origem As String, ByRef pasta_destino As String)
  927.  
  928.     Dim FSO As New FileSystemObject
  929.     FSO.CopyFile arq_origem, pasta_destino, True
  930.    
  931.     'Copy_One_File = "ok"
  932. End Function
  933.  
  934. Public Function xlCellTypeLastCell_Example_Row()
  935.     Dim LastRow As Long
  936.     With ActiveSheet
  937.         LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
  938.     End With
  939.     xlCellTypeLastCell_Example_Row = LastRow
  940. End Function
  941.  
  942.  
  943. Public Function ultimamilha(ByRef Filename() As Variant, ByRef tabelao As String) As String
  944.  
  945. 'CRIA A CONEXAO COM O BANCO
  946.    Set rs = New ADODB.Recordset
  947.  
  948.     ConnectDB
  949.  
  950.     rs.ActiveConnection = conexao
  951.     rs.LockType = adLockOptimistic
  952.     rs.CursorLocation = adUseClient
  953.     rs.CursorType = adOpenDynamic
  954.  
  955. 'DECLARACAO DE VARIAVEIS
  956.    Dim sheet As Worksheet
  957.     Dim celula, celula1 As Range
  958.     Dim LastRow As Long
  959.  
  960.     Dim Filter As String
  961.     Dim FilterIndex As Integer
  962. '    Dim filename As Variant
  963.    Dim remove As String
  964.     Dim i As Integer
  965.     ReDim Preserve ciclo(0)
  966.     ReDim Preserve ciclo_pop(0)
  967.     ReDim Preserve mux(0)
  968.     ReDim Preserve ciclo_placa(0)
  969.    
  970.     Dim modens() As modens
  971.     Dim placas() As placas
  972.     Dim portas() As portas
  973.     Dim tipo_modem() As tipo_modem
  974.     ReDim Preserve modens(0)
  975.     ReDim Preserve tipo_modem(0)
  976.     ReDim Preserve placas(0)
  977.     ReDim Preserve portas(0)
  978.  
  979.  
  980.     Dim m As Integer
  981.     Dim n As Integer
  982.  
  983.     rodada = 0
  984.  
  985.  
  986. 'NAO ATUALIZA A TELA
  987.    'Application.ScreenUpdating = False
  988.    
  989.     profile_folder = GetSpecialFolderPaths()
  990.    
  991.     operadora_caminho = profile_folder & "\SICOP\Auxiliar\operadoras.xlsx"
  992.     Workbooks.Open operadora_caminho, False
  993.    
  994.     hierarquias_caminho = profile_folder & "\SICOP\Auxiliar\hierarquias.xlsx"
  995.     Workbooks.Open hierarquias_caminho, False
  996.  
  997. '    ' File filters
  998. '    Filter = "Excel Files (*.xls),*.xls," & _
  999. '             "Text Files (*.txt),*.txt," & _
  1000. '             "All Files (*.*),*.*"
  1001. '    '   Default filter to *.*
  1002. '    FilterIndex = 3
  1003. '    ' Set Dialog Caption
  1004. '    Title = "Escolha o arquivo de circuitos "
  1005. '    ' Select Start Drive & Path
  1006. '    ChDrive ("C")
  1007. '    ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia\Facilidades\")
  1008. '    With Application
  1009. '        ' Set File Name Array to selected Files (allow multiple)
  1010. '        filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  1011. '        ' Reset Start Drive/Path
  1012. '        ChDrive (Left(.DefaultFilePath, 1))
  1013. '        ChDir (.DefaultFilePath)
  1014. '    End With
  1015. '    ' Exit on Cancel
  1016. '
  1017. '    If Not IsArray(filename) Then
  1018. '        MsgBox "Nenhum arquivo selecionado."
  1019. '        Exit Function
  1020. '    End If
  1021. 'CRIA 1 NOVA PLANILHA
  1022.    principal = ActiveWorkbook.Name
  1023.     Workbooks.Add
  1024.     ActiveWorkbook.Activate
  1025.     nova = ActiveWorkbook.Name
  1026.     Windows(nova).Activate
  1027.     Cells.Select
  1028.     Selection.NumberFormat = "@"
  1029.     Range("A1").Select
  1030.     'Workbooks.Add
  1031.    'ActiveWorkbook.Activate
  1032.    'plan_erro = ActiveWorkbook.Name
  1033.    Windows(principal).Activate
  1034.  
  1035. 'LOOP DOS ARQUIVOS SELECIONADOS - CONTROLE DE FACILIDADES
  1036.    ' Open Files
  1037.        
  1038.     For sasa = LBound(Filename) To UBound(Filename) - 1  ' FOR abre arquivos
  1039.        msg = msg & Filename(sasa) & vbCrLf    ' This can be removed
  1040.        'filename(sasa) = profile_folder & "\SICOP\Facilidades\Controle\" & filename(sasa)
  1041.        Workbooks.Open Filename(sasa), False
  1042.  
  1043.         arquivo = ActiveWorkbook.Name
  1044.         Windows(arquivo).Activate
  1045.        
  1046.         If arquivo Like "*Interior*" Then
  1047.  
  1048.             caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
  1049.  
  1050.         Else
  1051.  
  1052.             caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
  1053.  
  1054.         End If
  1055.  
  1056.         end2 = (caminhoarquivo & "\" & arquivo)
  1057.        
  1058.         'gera a planilha tabelao
  1059.        For Each sheet In ActiveWorkbook.Worksheets
  1060.        
  1061.            
  1062.             If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  1063.            
  1064.                 aba = sheet.Name
  1065.                 sheet.Select
  1066.                
  1067.                
  1068.                 Windows(arquivo).Activate
  1069.                 LastRow = xlCellTypeLastCell_Example_Row
  1070.                 Windows(arquivo).Activate
  1071.                 coluna = UsedRange_Example_Column
  1072.                 LastColumn = ConvertToLetter(coluna)
  1073.                 RangeSelect = "A1:" & LastColumn & LastRow
  1074.                 Windows(arquivo).Activate
  1075.                 Range(RangeSelect).Select
  1076.                 Selection.Copy
  1077.                 Windows(tabelao).Activate
  1078.                 LastRow = xlCellTypeLastCell_Example_Row
  1079.                 If LastRow = 1 Then
  1080.                     Range("C" & LastRow).Select
  1081.                 Else
  1082.                     Range("C" & LastRow + 1).Select
  1083.                 End If 'If LastRow = 1 Then
  1084.    
  1085.                 ActiveSheet.Paste
  1086.                 Cells.Select
  1087.                 Selection.WrapText = False
  1088.                 Cells.EntireColumn.AutoFit
  1089.                 If LastRow = 1 Then
  1090.                     old_lastrow = LastRow
  1091.                 Else
  1092.                     old_lastrow = LastRow + 1
  1093.                 End If
  1094.                
  1095.                 LastRow = xlCellTypeLastCell_Example_Row
  1096.                
  1097.                 For Each celula In Range("C" & old_lastrow & ":C" & LastRow)
  1098.                     linha = celula.Row
  1099.                     Range("A" & linha).Value = arquivo
  1100.                     Range("B" & linha).Value = aba
  1101.                     If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1102.                         Range("C" & linha).Select
  1103.                         subend = "'" & aba & "'!C" & linha
  1104.                         insere_anchor = celula.Value
  1105.                         If IsNumeric(insere_anchor) Then
  1106.                             insere_anchor = "'" & celula.Value
  1107.                         End If
  1108.                         ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=end2, SubAddress:=subend, TextToDisplay:=insere_anchor
  1109.                     End If 'If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1110.                
  1111.                 Next 'For Each celula In Range()
  1112.                
  1113.                 Windows(arquivo).Activate
  1114.            
  1115.             End If
  1116.            
  1117.        
  1118.         Next 'For Each sheet In ActiveWorkbook.Worksheets
  1119.        
  1120.         Windows(arquivo).Activate
  1121.         'caminhoarquivo = ActiveWorkbook.Path
  1122. 'DEFINE O CAMINHO DO ARQUIVO PARA CRIAR HYPERLINKS
  1123.        
  1124.    
  1125.  
  1126.         'TRATA CADA UMA DAS ABAS DAS PLANILHAS
  1127.        For Each sheet In ActiveWorkbook.Worksheets
  1128.  
  1129.             rpt = 0
  1130. 'IGNORA TODAS AS PLANILHAS QUE TEM RPT NO NOME - PLANILHAS DE RÁDIO
  1131. '            If sheet.Name Like "*RPT*" Then
  1132. '
  1133. '                rpt = 1
  1134. '
  1135. '            End If
  1136. 'IGNORA AS PLANILHAS QUE NÃO SÃO ULTIMA MILHA
  1137.            If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" And rpt = 0 Then
  1138. 'SELECIONA A ABA
  1139.                sheet.Select
  1140.  
  1141.                 aba = sheet.Name
  1142. 'TRATA AS PLANILHAS QUE NÃO SÃO VESPER
  1143.                If sheet.Name <> "Sites_Vesper" Then
  1144. 'ARMAZENA O NOME DA PLANILHA
  1145.                    aba1 = sheet.Name
  1146.                     'ENCONTRA A SIGLA DO POP NO BANCO DE DADOS MYSQL
  1147.                    sigla_pop = acha_sigla_pop(aba1)
  1148.  
  1149.                 End If    'If sheet.Name <> "Sites_Vesper" Then
  1150.  
  1151.  
  1152.                 If WorksheetFunction.CountA(Cells) > 0 Then
  1153.                     'Search for any entry, by searching backwards by Rows.
  1154.                    LastRow = Cells.Find(What:="*", After:=[A1], _
  1155.                                          SearchOrder:=xlByRows, _
  1156.                                          SearchDirection:=xlPrevious).Row
  1157.                 End If
  1158. 'RESETA AS VARIÁVEIS PARA CADA CICLO - UM CICLO NESSE CASO É O INTERVALO ENTRE AS LINHAS PRETAS, QUE REPRESENTAM UM ÚNICO EQUIPAMENTO
  1159. 'O CICLO COMEÇA DA LINHA 4 PORQUE A LINHA 3 É A PRIMEIRA PRETA
  1160.                inicio = 4
  1161.                 ReDim ciclo(0)
  1162.                 ReDim ciclo_pop(0)
  1163.                 ReDim mux(0)
  1164.                 ReDim ciclo_placa(0)
  1165.                 i = 0
  1166.                 'ADICIONA O NOME DO MULTIPLEXADOR AO ARRAY MUX
  1167.                mux(0) = Range("C3").Value
  1168.                
  1169.                 'AUMENTA O TAMANHO DO ARRAY MUX
  1170.                ReDim Preserve mux(UBound(mux) + 1)
  1171.  
  1172.                 For Each celula In Range("C4:C" & LastRow)
  1173.                     'DEFINE OS RANGES DE CADA EQUIPAMENTO (LINHA PRETA) NA PLANILHA
  1174.                    'ISSO SIGNIFICA CRIAR UMA ESTRUTURA DE LOOP PARA DA INTERVALO ENTRE LINHAS PRETAS NA PLANILHA
  1175. 'LINHA CORRENTE
  1176.                    linha = celula.Row
  1177. 'VERIFICA SE A LINHA É PRETA E CASO A PLANILHA SEJA A VESPER, UM NOVO POP É INICIADO
  1178.                    If celula.Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
  1179.                         aba1 = Range("G" & linha).Value
  1180.                         sigla_pop = acha_sigla_pop(aba1)
  1181.                     End If
  1182. 'ENCONTRA A LINHA PRETA E DEFINE O FINAL DO "CICLO" DE UM EQUIPAMENTO
  1183.                    If celula.Interior.ColorIndex = 1 Then
  1184.  
  1185.                         fim = linha - 1
  1186. 'ADICIONA O CICLO AO ARRAY CICLO PARA GERAR UMA CADEIA DE LOOPS PARA IDENTIFICAR AS PLACAS, MUXS E POPS (VESPER)
  1187.                        ciclo(i) = "E" & inicio & ":E" & fim
  1188.                         ciclo_pop(i) = "I" & inicio & ":I" & fim
  1189.                         ciclo_placa(i) = "K" & inicio & ":K" & fim
  1190.                         mux(i + 1) = RemoveSpaces(UCase(Range("C" & linha).Value))
  1191.  
  1192. 'AUMENTA O TAMANHO DOS ARRAYS SEM PERDER OS DADOS
  1193.                        ReDim Preserve ciclo(UBound(ciclo) + 1)
  1194.                         ReDim Preserve ciclo_pop(UBound(ciclo_pop) + 1)
  1195.                         ReDim Preserve mux(UBound(mux) + 1)
  1196.                         ReDim Preserve ciclo_placa(UBound(ciclo_placa) + 1)
  1197.  
  1198.                         i = i + 1
  1199. 'REINICIA A VARIAVEL 'INICIO' PARA DAR CONTINUIDADE AO LOOP
  1200.                        inicio = linha + 1
  1201.  
  1202.                     End If    'If celula.Interior.ColorIndex = 1 Then
  1203.  
  1204.                 Next    ' For Each celula In Range("C4:C" & LastRow)
  1205. 'APOS IDENTIFICAR TODOS OS CICLOS, FINALIZA COM A ULTIMA LINHA PREENCHIDA DO ARQUIVO
  1206.                fim = LastRow
  1207.  
  1208.                 ciclo(i) = "E" & inicio & ":E" & fim
  1209.                 ciclo_pop(i) = "I" & inicio & ":I" & fim
  1210.                 ciclo_placa(i) = "K" & inicio & ":K" & fim
  1211.  
  1212.  
  1213.  
  1214. 'ESSE CICLO PEGA AS INFORMACOES DE CADA PLACA (COLUNA K) PARA IDENTIFICA-LAS CORRETAMENTE
  1215.                For i = 0 To UBound(ciclo_placa)
  1216.                     'RENOMEIA AS PLACAS DE CADA RANGE
  1217.  
  1218.                     For Each celula In Range(ciclo_placa(i))
  1219.  
  1220.                         linha_h = celula.Row
  1221.  
  1222.  
  1223.                         If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1224. 'PEGA O NOME DA PLACA
  1225.                            placa = celula.Value
  1226.                             placa = UCase(RemoveSpaces((placa)))
  1227. 'ATUALIZA O OBJETO 'PLACAS' COM O NOME DA PLACA E UM SEQUENCIAL PARA IDENTIFICAR QUANTAS PLACAS DO MESMO TIPO EXISTEM NAQUELE EQUIPAMENTO
  1228.                            For t = 0 To UBound(placas)
  1229.                                 'PEGA A SEQUENCIA DE CADA PLACA REPETIDA
  1230.                                If placa = placas(t).nome Then
  1231.                                     placas(t).seq = placas(t).seq + 1
  1232.                                     seq_placa = placas(t).seq
  1233.                                     GoTo encontrado_placa
  1234.                                 End If    ' If placa = placas(t).nome Then
  1235.                            Next    ' For t = 0 To UBound(placa)
  1236.  
  1237.                             'SO SERA EXECUTADO SE NAO ACHAR PLACA
  1238. 'CASO NÃO EXISTA NENHUMA OCORRENCIA DA PLACA NO OBJETO 'PLACAS', ADICIONA UM NOVO ITEM COM O NOME DA PLACA NOVA
  1239.                            placas(UBound(placas)).nome = placa
  1240.                             placas(UBound(placas)).seq = 1
  1241.                             seq_placa = 1
  1242.                             ReDim Preserve placas(UBound(placas) + 1)
  1243.                             'SO SERA EXECUTADO SE NAO ACHAR PLACA
  1244.  
  1245.  
  1246. encontrado_placa:
  1247. 'APOS A PLACA TER SIDO CRIADA OU IDENTIFICADA, CRIA UM NOME PARA A PLACA NOS MOLDES - TIPO_DA_PLACA.MUX_ONDE_SE_ENCONTRA.SEQUENCIAL
  1248.                            nome_placa_mod = placa & "." & mux(i) & "." & seq_placa
  1249.  
  1250.                             celula.Value = nome_placa_mod
  1251.                             'REINICIA O ARRAY DE PORTAS PARA IDENTICAR AS PORTAS DA PLACA ATUAL
  1252.                            ReDim portas(0)
  1253.  
  1254.                         End If    ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1255. 'INICIA A VARIAVEL DAS PORTAS
  1256.                        porta = ""
  1257.  
  1258. 'VERIFICA SE A EXISTE UMA PORTA ASSOCIADA AQUELA PLACA E SE A CELULA NAO ESTA VAZIA
  1259.                        If Not IsEmpty(celula.Next.Next.Value) And RemoveSpaces((celula.Next.Next.Value)) <> "" Then
  1260. 'ASSOCIA A PORTA A VARIAVEL
  1261.                            porta = celula.Next.Next.Value
  1262.                             porta = UCase(RemoveSpaces((porta)))
  1263.  
  1264.                         End If
  1265.  
  1266.                         If porta <> "" Then
  1267.                             'PEGA AS PORTAS DA PLACA
  1268. 'ASSOCIA CADA PORTA DAQUELA PLACA AO OBJETO 'PORTAS'
  1269.                            For t = 0 To UBound(portas)
  1270.  
  1271.                                 If porta = portas(t).nome Then
  1272.                                     portas(t).seq = portas(t).seq + 1
  1273.                                     seq_porta = portas(t).seq
  1274.                                     GoTo achou_porta
  1275.                                 End If
  1276.                             Next
  1277. 'CASO A PORTA NAO EXISTA, CRIA UMA NOVA ENTRADA
  1278.                            'SO SERA EXECUTADO SE NAO ACHAR PORTA
  1279.  
  1280.                             portas(UBound(portas)).nome = porta
  1281.                             portas(UBound(portas)).seq = 1
  1282.                             seq_porta = 1
  1283.                             ReDim Preserve portas(UBound(portas) + 1)
  1284.  
  1285.                             'SO SERA EXECUTADO SE NAO ACHAR PORTA
  1286.  
  1287. achou_porta:
  1288. 'CRIA UM IDENTIFICADOR PARA A PORTA NO FORMATO PORTA.SEQUENCIAL
  1289. 'CASO NAO EXISTA A LETRA P NO CAMPO ADICIONA ESSA LETRA AO NOME DA PORTA E GRAVA NA CELULA DA PORTA
  1290.                            If InStr(1, porta, "P") = 0 Then
  1291.  
  1292.                                 celula.Next.Next.Value = "'" & porta & "." & seq_porta
  1293.  
  1294.                             Else
  1295.  
  1296.                                 celula.Next.Next.Value = porta & "." & seq_porta
  1297.  
  1298.                             End If
  1299. 'VARIAVEL PARA VERIFICACAO SE A PORTA ESTA COM A CELULA HACHURADA
  1300.                            porta_hachurada = celula.Next.Next.Value
  1301.  
  1302.                             hachu_seq = 1
  1303.  
  1304.  
  1305.  
  1306.                         End If    'If porta <> "" Then
  1307. 'IF PARA VERIFICAR SE A PORTA ESTA HACHURADA. CASO ESTEJA, E A CELULA ESTEJA VAZIA, PREENCHE O DADO COM A ULTIMA PORTA ENCONTRADA
  1308.  
  1309.                         If IsEmpty(Range("M" & linha_h)) And RemoveSpaces(Range("M" & linha_h).Value) = "" And (Range("M" & linha_h).Interior.Pattern = 14 Or Range("M" & linha_h).Interior.Pattern = -4162) And Not IsEmpty(Range("C" & linha_h)) And RemoveSpaces(Range("C" & linha_h).Value) <> "" Then
  1310.  
  1311.                             Range("M" & linha_h).Value = porta_hachurada & "." & hachu_seq
  1312.                             hachu_seq = hachu_seq + 1
  1313.  
  1314.  
  1315.                         End If
  1316.  
  1317.  
  1318.                     Next    ' For Each celula In Range(ciclo_placa(i))
  1319. 'REINICIA O ARRAY DE PLACAS
  1320.                    ReDim placas(0)
  1321.  
  1322.                 Next    ' For i = 0 To UBound(ciclo_placa)
  1323.  
  1324.  
  1325. 'LOOP PARA IDENTIFICAR OS MODENS DO LADO DO POP - COLUNA E
  1326.                For i = 0 To UBound(ciclo)    'COLUNA E
  1327.  
  1328.                     For Each celula In Range(ciclo(i))
  1329.  
  1330.                         linha = celula.Row
  1331.                        
  1332.  
  1333. 'VERIFICA SE A CELULA ESA VAZIA, SE ESTIVER, 'RESETA' OS DADOS DA CELULA. ISSO PRECISA SER FEITO PORQUE MUITAS VEZES A FORMATACAO CONDICIONAL
  1334. 'SOBREPOE OS DADOS REAIS DA CELULA. EX. UMA CELULA ESTÁ COM FUNDO PRETO, MAS DECIDO A FORMATACAO CONDICIONAL ESSE ITEM APARECE BRANCO/VERDE/AMARELO/LARANJA
  1335.                        If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
  1336.  
  1337.                             Range("E" & linha).Select
  1338.                             Selection.Clear
  1339. '                           Range("E" & linha).Font.Bold = False
  1340.  
  1341.                         End If
  1342. 'FAZ A MESMA VERIFICACAO ACIMA, MAS PARA A PORTA
  1343.                        If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
  1344.  
  1345.                             Range("F" & linha).Select
  1346.                             Selection.Clear
  1347. '                          Range("F" & linha).Font.Bold = False
  1348.  
  1349.                         End If
  1350.  
  1351.                     Next 'For Each celula In Range(ciclo(i))
  1352.  
  1353.  
  1354.                     For Each celula In Range(ciclo(i))
  1355.  
  1356.                         linha = celula.Row
  1357. 'VERIFICAR SE AMBAS AS CELULAS DA COLUNA 'E' E 'F' NAO ESTAO VAZIAS
  1358.  
  1359.                         If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" And Range("F" & linha).Font.Color <> Range("E" & linha).Font.Color Then
  1360.  
  1361. 'VERIFICA SE A COR DA FONTE DO EQUIPAMENTO É DIFERENTE DA COR DA PORTA DAQUELE EQUIPAMENTO
  1362.                            If Range("E" & linha).Font.Color <> 0 And Range("F" & linha).Font.Color = 0 Then
  1363. 'EM CASO POSITIVO, COPIA A COR DA FONTE DO EQUIPAMENTO PARA SUA RESPECTIVA PORTA
  1364.                                Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  1365. 'FAZ A VERIFICACAO CONTRARIA - COR DA PORTA = COR DO EQUIPAMENTO
  1366.                            ElseIf Range("F" & linha).Font.Color <> 0 And Range("E" & linha).Font.Color = 0 Then
  1367.  
  1368.                                 Range("E" & linha).Font.Color = Range("F" & linha).Font.Color
  1369.  
  1370.                             End If
  1371.  
  1372.                         End If
  1373.  
  1374. 'VERIFICA SE HÁ UM CIRCUITO ASSOCIADO AQUELE EQUIPAMENTO E SE O EQUIPAMENTO E A PORTA EXISTEM
  1375.                        If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces((Range("C" & linha).Value)) <> "" And IsEmpty(Range("E" & linha).Value) And RemoveSpaces((Range("E" & linha).Value)) = "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces((Range("F" & linha).Value)) = "" Then
  1376. 'CASO NAO EXISTA EQUIPAMENTO, É CRIADO O EQUIPAMENTO 'CABO' COM SUA RESPECTIVA PORTA 'PO1'
  1377.  
  1378.                             Range("E" & linha).Value = "CABO"
  1379.                             Range("E" & linha).Font.Color = 0
  1380.                             Range("F" & linha).Value = "PO1"
  1381.                             Range("F" & linha).Font.Color = 0
  1382.  
  1383.  
  1384.                         End If
  1385.                        
  1386.                        
  1387.  
  1388. 'VERIFICA SE EXISTE UM EQUIPAMENTO MAS NAO EXISTE UMA PORTA ASSOCIADA A ELE
  1389.                        If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
  1390. 'CASO O EQUIPAMENTO SEJA UM ASGA, ADICIONA A PORTA P1 PARA ELE
  1391.                            If InStr(1, Range("E" & linha).Value, "ASGA") <> 0 Then
  1392.                            
  1393.                                 Range("F" & linha).Value = "P1"
  1394.                                
  1395.                             Else
  1396.                             'SE NAO FOR UM EQUIPAMENTO ASGA, CRIA A PORTA ESPECIAL 1 - PE1
  1397.                                Range("F" & linha).Value = "PE1"
  1398.                            
  1399.                             End If
  1400.                             'COLOCA A COR DA PORTA IGUAL A DO EQUIPAMENTO
  1401.                            
  1402.                             Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  1403.  
  1404.                         End If
  1405.  
  1406. 'NAO SEI PRA QUE ESSE CODIGO ABAIXO FOI COMENTADO.
  1407. '                        If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
  1408. '
  1409. '                            Range("F" & linha).Value = "PE1"
  1410. '                            Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  1411. '
  1412. '                        End If
  1413.  
  1414. 'VERIFICA SE EXISTE O EQUIPAMENTO, SE A PORTA E A PORTA ESTÁ VAZIA E SE O EQUIPAMENTO É UM DM706
  1415.                        If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" And UCase(Range("E" & linha).Value) = "DM706" Then
  1416. 'CASO SEJA, ADICIONA A PORTA P1 E REPETE A COR PARA O EQUIPAMENTO E PORTA
  1417.                            Range("F" & linha).Value = "P1"
  1418.                             Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  1419.  
  1420.                         End If
  1421.  
  1422. 'CASO SEJA IDENTIFICADO O ITEM 'CPU64' NA COLUNA I, REMOVE ELE - NAO SERVE PARA NADA
  1423.  
  1424.                         If RemoveSpaces(UCase(Range("I" & linha).Value)) = "CPU64" Then
  1425.  
  1426.                             Range("I" & linha).Select
  1427.                             Selection.Clear
  1428.  
  1429.                         End If
  1430.  
  1431.                         'VERIFICA SE A CELULA DO EQUIPAMENTO NAO ESTA VAZIA
  1432.                        If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1433. 'ASSOCIA O EQUIPAMENTO A VARIAVEL MODEM
  1434.                            modem = UCase(RemoveSpaces(celula.Value))
  1435.                             'CASO O EQUIPAMENTO SEJA UM CABO, MUDA O NOME PARA CABO_CLI
  1436.                            If modem = "CABO" Then
  1437.                                 modem = "CABO_CLI"
  1438.                             End If
  1439. 'ASSOCIA O NOME DO MODEM AO OBJETO-ARRAY MODENS
  1440.                            modens(UBound(modens)).nome = modem
  1441.  
  1442.                             'SE O EQUIPAMENTO NAO FOR UM CABO, ADICIONA A COR DA FONTE AO OBJETO-ARRAY
  1443.                            If modem <> "CABO" Then
  1444.  
  1445.                                 modens(UBound(modens)).cor_fonte = celula.Font.Color
  1446. 'EM CASO CONTRARIO, SETA A COR COMO 'AUTOMATICO'
  1447.                            Else
  1448.  
  1449.                                 modens(UBound(modens)).cor_fonte = 0
  1450.  
  1451.                             End If
  1452. 'ADICIONA A LINHA DE ONDE AQUELE MODEM VEIO
  1453.                            modens(UBound(modens)).linha = celula.Row
  1454.  
  1455. 'VERIFICA SE JÁ EXISTE O TIPO DE MODEM NA BASE, EM CASO NEGATIVO, CRIA O MODEM. EM CASO POSITIVO ADICIONA UM SEQUENCIAL PARA DIFERENCIACAO
  1456.                            For t = 0 To UBound(tipo_modem)
  1457.  
  1458.                                 If tipo_modem(t).nome = modem Then
  1459.                                     GoTo encontrado_tipo_modem
  1460.                                 End If
  1461.  
  1462.                             Next    'For t = 0 To UBound(tipo_modem)
  1463.  
  1464.                             'SO SERA EXECUTADO SE NAO ACHAR
  1465.  
  1466.                             tipo_modem(UBound(tipo_modem)).nome = modem
  1467.                             tipo_modem(UBound(tipo_modem)).seq = 1
  1468.                             ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
  1469.  
  1470.                             'SO SERA EXECUTADO SE NAO ACHAR
  1471.  
  1472. encontrado_tipo_modem:
  1473.  
  1474. 'AUMENTA O TAMANHO DO ARRAY
  1475.                            ReDim Preserve modens(UBound(modens) + 1)
  1476.  
  1477.  
  1478.  
  1479.                         End If  ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1480.  
  1481.  
  1482.  
  1483.                     Next    'For Each celula In Range(ciclo(i))
  1484.  
  1485. 'FORMATA O TIPO DO MODEM E SUA COR PARA SER INSERIDO NA CELULA
  1486.                    For K = 0 To (UBound(modens) - 1)
  1487.  
  1488.                         nome_modem = modens(K).nome
  1489.                         cor_fonte_modem = modens(K).cor_fonte
  1490.  
  1491.                         For u = 0 To (UBound(tipo_modem) - 1)
  1492.  
  1493.                             If tipo_modem(u).nome = nome_modem Then
  1494.                                 seq_modem = tipo_modem(u).seq
  1495.                                 posicao_seq_modem = u
  1496.                                 Exit For
  1497.                             End If    'If tipo_modem(u).nome = nome_modem Then
  1498.  
  1499.                         Next    'For u = 0 To (UBound(tipo_modem) - 1)
  1500.  
  1501. 'IDENTIFICA A SIGLA DO CLIENTE A PARTIR DA DESIGNACAO PARA COMPOR O NOME DO MODEM
  1502.                        circuito_cliente = Range("C" & modens(K).linha).Value
  1503.  
  1504.                         sigla_cliente = ""
  1505.  
  1506.                         sigla_cliente = detecta(circuito_cliente, arquivo, mux(i))
  1507.  
  1508.                         If sigla_cliente = "" Then
  1509.  
  1510.                             sigla_cliente = mux(i)
  1511.  
  1512.                         End If
  1513.  
  1514. 'GERA O NOME DO MODEM PARA ALTERAR A CELULA
  1515.                        nome_modem_mod = nome_modem & "." & sigla_cliente & "." & seq_modem
  1516. 'CASO A COR SEJA AUTOMATICA (0) O MODEM SERÁ INSERIDO COM O SEQUENCIAL '1'. SENDO ASSIM PULA A ETAPA DE IDENTIFICAR A COR E SEQUENCIAL DO MODEM (LOGO ABAIX0)
  1517.                        If cor_fonte_modem = 0 Then
  1518.  
  1519.                             modens(K).novo_nome = nome_modem_mod
  1520.                             tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  1521.                             GoTo linha_zero
  1522.  
  1523.                         End If    'If cor_fonte_modem = 0 Then
  1524.  
  1525. 'IDENTIFICA SE JÁ EXISTE O MODEM PELA COR DA FONTE, CASO EXISTA, PEGA O NOME DELE
  1526.                        For y = 0 To (UBound(modens) - 1)
  1527.  
  1528.                             If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  1529.  
  1530.                                 modens(y).novo_nome = nome_modem_mod
  1531.  
  1532.                             End If    'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  1533.  
  1534.  
  1535.                         Next    'For y = 0 To (UBound(modens) - 1)
  1536. 'ATUALIZA O SEQUENCIAL DO TIPO DO MODEM
  1537.                        tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  1538. linha_zero:
  1539. 'ATUALIZA O VALOR DA LINHA DO MODEM
  1540.                        Range("E" & modens(K).linha).Value = nome_modem_mod
  1541.                         Range("E" & modens(K).linha).Font.Color = Range("F" & modens(K).linha).Font.Color
  1542. 'CASO O MODEM SEJA CABO_CLI, CRIA A PORTA OTICA 1 - 'PO1'
  1543.                        If tipo_modem(posicao_seq_modem).nome = "CABO_CLI" Then
  1544.  
  1545.                             Range("E" & modens(K).linha).Next.Value = "PO1"
  1546.  
  1547.                         End If    'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
  1548.  
  1549.                     Next    ' For k = 0 To UBound(modens)
  1550.  
  1551.                     For Each celula In Range(ciclo(i))
  1552. 'LOOP PARA IDENTIFICAR QUAIS MODENS TEM COR DIFERENTE DA AUTOMATICA E SUAS PORTAS ASSOCIADAS
  1553.                        'COLOCA AS CORES DAS PORTAS NOS MODENS!!! (LADO CLIENTE)
  1554. 'VERIFICA SE A COR É DIFERENTE DE 0
  1555.                        If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
  1556.  
  1557.                             porta_cliente = celula.Next.Value
  1558.                             cor_porta_cliente = celula.Next.Font.Color
  1559.                             cor_encontrada = 0
  1560. 'PROCURA PELA COR NO ARRAY MODENS
  1561.                            For K = 0 To (UBound(modens) - 1)
  1562. 'CASO ENCONTRE, ASSOCIA O EQUIPAMENTO DA MESMA COR À PORTA ASSOCIADA A ELE
  1563.                                If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  1564.  
  1565.                                     celula.Value = modens(K).novo_nome
  1566.  
  1567.                                     '                                    celula.Font.Color = modens(k).cor_fonte
  1568.  
  1569.                                 End If    'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  1570.  
  1571.  
  1572.  
  1573.                             Next    'For k = 0 To (UBound(modens) - 1)
  1574.  
  1575. 'IF DE VERIFICACAO DEBUG
  1576. '                        If IsEmpty(celula) And RemoveSpaces(celula.Value) = "" Then
  1577. '
  1578. '                            laleq1a = 0
  1579. '
  1580. '                        End If
  1581.  
  1582.  
  1583.  
  1584.                         End If    'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
  1585.  
  1586.  
  1587.  
  1588.                     Next    'Each celula In Range(ciclo(i))
  1589. 'REINICIA OS MODENS E TIPOS DE MODENS PARA O PROXIMO MULTIPLEXADOR
  1590.                    ReDim modens(0)
  1591.                     ReDim tipo_modem(0)
  1592.  
  1593.                 Next    'For i = 0 To UBound(ciclo)
  1594.  
  1595.                 For i = 0 To UBound(ciclo_pop)    'CICLO MODENS LADO POP COLUNA I
  1596. 'LOOP QUE FAZ AS MESMAS COISAS DO LOOP ANTERIOR, SÓ QUE DESSA VEZ DO LADO DO CLIENTE, COLUNA I
  1597.                    For Each celula In Range(ciclo(i))
  1598.  
  1599.                         linha = celula.Row
  1600.                        
  1601.  
  1602.                         If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
  1603.  
  1604.                             Range("I" & linha).Font.Color = 0
  1605.                             Range("I" & linha).Font.Bold = False
  1606.  
  1607.                         End If
  1608.  
  1609.                         If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
  1610.  
  1611.                             Range("J" & linha).Font.Color = 0
  1612.                             Range("J" & linha).Font.Bold = False
  1613.  
  1614.                         End If
  1615.  
  1616.                     Next
  1617.  
  1618.                     For Each celula In Range(ciclo_pop(i))
  1619.  
  1620.                         linha = celula.Row
  1621.                        
  1622.  
  1623.                         If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1624.  
  1625.                             modem = UCase(RemoveSpaces(celula.Value))
  1626.                             modens(UBound(modens)).nome = modem
  1627.                             modens(UBound(modens)).cor_fonte = celula.Font.Color
  1628.                             modens(UBound(modens)).linha = celula.Row
  1629.  
  1630.                             If modem <> "CPU64" Then
  1631.                                 For t = 0 To UBound(tipo_modem)
  1632.  
  1633.                                     If tipo_modem(t).nome = modem Then
  1634.                                         GoTo encontrado_tipo_modem_pop
  1635.                                     End If
  1636.  
  1637.                                 Next    'For t = 0 To UBound(tipo_modem)
  1638.  
  1639.                                 'SO SERA EXECUTADO SE NAO ACHAR
  1640.  
  1641.                                 tipo_modem(UBound(tipo_modem)).nome = modem
  1642.                                 tipo_modem(UBound(tipo_modem)).seq = 1
  1643.                                 ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
  1644.  
  1645.                                 'SO SERA EXECUTADO SE NAO ACHAR
  1646.  
  1647. encontrado_tipo_modem_pop:
  1648.  
  1649.  
  1650.                                 ReDim Preserve modens(UBound(modens) + 1)
  1651.  
  1652.                             End If    'If modem <> "CPU64" Then
  1653.  
  1654.                         End If  ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  1655.  
  1656.  
  1657.  
  1658.                     Next    'For Each celula In Range(ciclo_pop(i))
  1659.  
  1660.                     For K = 0 To (UBound(modens) - 1)
  1661.  
  1662.                         nome_modem = modens(K).nome
  1663.                         cor_fonte_modem = modens(K).cor_fonte
  1664.  
  1665.                         For u = 0 To (UBound(tipo_modem) - 1)
  1666.  
  1667.                             If tipo_modem(u).nome = nome_modem Then
  1668.                                 seq_modem = tipo_modem(u).seq
  1669.                                 posicao_seq_modem = u
  1670.                                 Exit For
  1671.                             End If    'If tipo_modem(u).nome = nome_modem Then
  1672.  
  1673.                         Next    'For u = 0 To (UBound(tipo_modem) - 1)
  1674.  
  1675. 'VERIFICA SE O MODEM É UM MOFL4E1, AS PORTAS DELE SAO TRATADAS DE FORMA DIFERENTE
  1676.                        If nome_modem = "MOFL4E1" Then
  1677.  
  1678.                             seq_modem = Mid(Range("J" & modens(K).linha).Value, 1, 1)
  1679.  
  1680.                         End If
  1681.                        
  1682.                         If nome_modem <> "DM705" Then
  1683.                        
  1684.                              nome_modem_mod = nome_modem & "." & mux(i) & "." & seq_modem
  1685.                        
  1686.                         Else
  1687.                            
  1688.                             mod_dm705 = ""
  1689.                            
  1690.                             For Each dm In Range("G" & linha & ":G" & LastRow)
  1691.                              
  1692.                                 nome_dm = dm.Value
  1693.                                 nome_dm = UCase(nome_dm)
  1694.                                
  1695.                                 If dm.Interior.ColorIndex = 1 Then
  1696.                                
  1697.                                     If InStr(1, nome_dm, "P/") <> 0 And InStr(1, nome_dm, "(") <> 0 And InStr(1, nome_dm, ")") <> 0 Then
  1698.                                    
  1699.                                         mod_dm705 = Trim(Range("C" & dm.Row).Value)
  1700.                                    
  1701.                                         Exit For
  1702.                                    
  1703.                                         'seek_sigla1 = Mid(nome_dm, InStrRev(nome_dm, "P/") + 2, Len(nome_dm))
  1704.                                        'seek_sigla2 = Mid(seek_sigla1, 1, Len(seek_sigla1) - 1)
  1705.                                    
  1706.                                     End If
  1707.                                                      
  1708.                                 End If
  1709.                              
  1710.                             Next
  1711.                        
  1712.                             If mod_dm705 <> "" Then
  1713.                            
  1714.                                 nome_modem_mod = nome_modem & "." & mod_dm705 & "." & seq_modem
  1715.                            
  1716.                             Else
  1717.                            
  1718.                                 nome_modem_mod = nome_modem & "." & mux(i) & "." & seq_modem
  1719.                            
  1720.                             End If
  1721.                        
  1722.                         End If
  1723.  
  1724.                        
  1725.  
  1726.                         If cor_fonte_modem = 0 Then
  1727.  
  1728.                             modens(K).novo_nome = nome_modem_mod
  1729.                             tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  1730.                             GoTo linha_zero_pop
  1731.  
  1732.                         End If    'If cor_fonte_modem = 0 Then
  1733.  
  1734.                         For y = 0 To (UBound(modens) - 1)
  1735.  
  1736.                             If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  1737.  
  1738.                                 modens(y).novo_nome = nome_modem_mod
  1739.  
  1740.  
  1741.                             End If    'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  1742.  
  1743.  
  1744.                         Next    'For y = 0 To (UBound(modens) - 1)
  1745.  
  1746.                         tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  1747. linha_zero_pop:
  1748.  
  1749.                         Range("I" & modens(K).linha).Value = nome_modem_mod
  1750.                         Range("I" & modens(K).linha).Font.Color = Range("J" & modens(K).linha).Font.Color
  1751. 'CASO O MODEM SEJA UM CABO_POP, CRIA UMA PORTA OTICA 1 PARA ELE PO1
  1752.                        If tipo_modem(posicao_seq_modem).nome = "CABO_POP" Then
  1753.  
  1754.                             Range("I" & modens(K).linha).Next.Value = "PO1"
  1755.  
  1756.                         End If    'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
  1757.  
  1758.                     Next    ' For k = 0 To UBound(modens)
  1759.  
  1760.                     For Each celula In Range(ciclo_pop(i))
  1761.  
  1762.                         linha_plan = celula.Row
  1763. 'VERIFICA SE A LINHA ACIMA DA LINHA ATUAL É PRETA E SE A PLANILHA É VESPER. EM CASO POSITIVO PEGA A SIGLA DO POP
  1764.                        If Range("C" & linha_plan - 1).Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
  1765.                             aba1 = Range("G" & linha_plan - 1).Value
  1766.                             sigla_pop = acha_sigla_pop(aba1)
  1767.                         End If
  1768. 'PEGA OS DADOS DA CELULA PARA GERAR O HYPERLINK
  1769.                        subend = ("'" & aba & "'!" & RemoveDolars(celula.Address))
  1770.                         'strcell = celula.Address
  1771.  
  1772.                         linha_preta = 0
  1773. 'RESETA AS VARIAVEIS QUE SAO UTILIZADAS QUANDO O MODEM É FLEX
  1774.                        nome_flex = ""
  1775.                         numero_flex = ""
  1776.                         slot_flex = ""
  1777.                         porta_flex = ""
  1778.  
  1779. 'VERIFICA SE A PORTA ESTÁ PREENCHIDA, SE A COR DA FONTE É DIFERENTE DE 0 E SE NÃO EXISTEM OS CARACTERES ESPECIAIS '-' E '/' NA PORTA
  1780.                        If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 And InStr(celula.Next.Value, "/") = 0 And InStr(celula.Next.Value, "-") = 0 Then
  1781. 'PEGA OS DADOS DAS PORTAS DO EQUIPAMENTO DO CLIENTE
  1782.                            porta_cliente = celula.Next.Value
  1783.                             cor_porta_cliente = celula.Next.Font.Color
  1784. 'VERIFICA SE A COR JÁ FOI UTILIZADA EM ALGUM MODEM ANTERIOR AO ATUAL
  1785.                            For K = 0 To (UBound(modens) - 1)
  1786.  
  1787.                                 If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  1788.  
  1789.                                     celula.Value = modens(K).novo_nome
  1790.  
  1791.                                 End If    'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  1792.  
  1793.                             Next    'For k = 0 To (UBound(modens) - 1)
  1794. 'CASO A PORTA TENHA '/' OU '-' ELA É DE UM MODEM FLEX
  1795.                        ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") < 2 Then
  1796. 'SEPARA AS INFORMAÇÕES DA PORTA DO MODEM FLEX
  1797.                            celula.Select
  1798.                             celula.Next.Select
  1799.                             celula.Next.Font.Color = 0
  1800.                             nome_flex = "MOFL4E1"
  1801.                             numero_flex = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 2)
  1802.                             slot_flex = Mid(celula.Next.Value, 2, InStr(1, celula.Next.Value, "/") - 2)
  1803.                             porta_flex = "P" & Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
  1804.                             celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
  1805.  
  1806.  
  1807.                         ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") <> 0 And countSeparators(celula.Next.Value, "/") < 2 Then
  1808.  
  1809. 'CASO NAO SEJA UM MODEM FLEX, A PORTA É DE UM MODEM AX4E1
  1810.                            celula.Next.Value = UCase(RemoveSpaces((celula.Next.Value)))
  1811.                             celula.Next.Font.Color = 0
  1812.                             nome_flex = "MOAX4E1"
  1813.                             tira_mux = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "-") + 1, Len(celula.Next.Value))
  1814.                             numero_flex = Mid(tira_mux, 1, 1)
  1815.                             tira_numero = Mid(tira_mux, InStr(1, tira_mux, "S"), Len(tira_mux))
  1816.                             slot_flex = Mid(tira_numero, 1, InStr(1, tira_numero, "/") - 1)
  1817.                             tira_slot = Mid(tira_numero, InStr(1, tira_numero, "/") + 1, Len(tira_numero))
  1818.                             interface = Mid(tira_slot, 1, InStr(1, tira_slot, "P") - 1)
  1819.                             slot_flex = slot_flex & "/" & interface
  1820.                             porta_flex = Mid(tira_slot, InStr(1, tira_slot, interface) + 1, Len(tira_slot))
  1821.                             celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
  1822.  
  1823. 'CASO A PORTA NAO SEJA NEM DE UM MODEM FLEX, NEM DE UM AX4E1, É DE UM MDOEM DM4E1S
  1824.                        ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") = 2 Then
  1825.  
  1826.                             numero_dm4 = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 1)
  1827.                             slot_porta = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
  1828.  
  1829.                             celula.Value = "DM4E1S13." & mux(i) & "." & numero_dm4
  1830.                             celula.Next.Value = "'" & slot_porta
  1831.  
  1832.  
  1833.                         End If    'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
  1834.  
  1835.  
  1836. 'AUMENTA EM 1 A CONTAGEM DA LINHA PRETA PARA O PROXIMO LOOP
  1837.                        If celula.Interior.ColorIndex = 1 Then
  1838.                             linha_preta = linha_preta + 1
  1839.                         End If
  1840.  
  1841.                         If Not IsEmpty(Range("L" & linha_plan).Value) And RemoveSpaces(Range("L" & linha_plan).Value) <> "" Then
  1842. 'PEGA O VALOR DA CELULA QUE CONTEM O SLOT
  1843.                            slot_plan = Range("L" & linha_plan).Value
  1844.  
  1845.                         End If
  1846.  
  1847.                         If Not IsEmpty(Range("K" & linha_plan).Value) And RemoveSpaces(Range("K" & linha_plan).Value) <> "" Then
  1848. 'PEGA O VALOR DA CELULA QUE CONTEM A PLACA
  1849.                            placa_plan = Range("K" & linha_plan).Value
  1850.  
  1851.                         End If
  1852. 'VERIFICA SE EXISTE UM CIRCUITO EXISTE E ESTE NÃO ESTÁ VAZIO
  1853.                        If Not IsEmpty(Range("C" & linha_plan).Value) And RemoveSpaces((Range("C" & linha_plan).Value)) <> "" Then
  1854.  
  1855.  
  1856.                             circuito_plan = Range("C" & linha_plan).Value
  1857.                             pop_mux_plan = sigla_pop
  1858.                             nome_mux_plan = mux(i)
  1859.                             tipo_mux_plan = acha_tipo_equip(nome_mux_plan)
  1860.                            
  1861.                             If tipo_mux_plan = "99" Then
  1862.                            
  1863.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(celula.Address))
  1864.                                 ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, celula.Value, "Erro - Tipo de Multiplexador não identificado : " & nome_mux_plan)
  1865.                                vazia = 1
  1866.                            
  1867.                             End If
  1868.  
  1869.  
  1870.  
  1871.  
  1872. 'PEGA OS DADOS DA PORTA DO MUX - COLUNA M
  1873.                            If Not IsEmpty(Range("M" & linha_plan).Value) And RemoveSpaces(Range("M" & linha_plan).Value) <> "" Then
  1874.  
  1875.                                 porta_mux_plan = Range("M" & linha_plan).Value
  1876.  
  1877.                             Else
  1878.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("M" & linha_plan).Address))
  1879.                                 ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("M" & linha_plan).Value, "Porta do Multiplexador não encontrada.")
  1880.                                vazia = 1
  1881.                            
  1882.                             End If
  1883. 'PEGA OS DADOS DO MODEM DO LADO DO POP
  1884.  
  1885.                             If Not IsEmpty(Range("I" & linha_plan).Value) And RemoveSpaces(Range("I" & linha_plan).Value) <> "" Then
  1886.  
  1887.                                 modem_pop_plan = Range("I" & linha_plan).Value
  1888.  
  1889.                                 tipo_modem_pop_plan = Mid(modem_pop_plan, 1, InStr(1, modem_pop_plan, ".") - 1)
  1890.  
  1891.                             Else
  1892. 'CASO ESTEJA VAZIO, CRIA-SE O CABO_POP
  1893.                                modem_pop_plan = "CABO_POP"
  1894.                                 tipo_modem_pop_plan = "CABO_POP"
  1895.  
  1896.                                 'VALIDA O TIPO DE MODEM DO LADO DO POP E CASO EXISTA, ADICIONA UM SEQUENCIAL A ELE
  1897.                                For t = 0 To UBound(tipo_modem)
  1898.  
  1899.                                     If tipo_modem(t).nome = modem_pop_plan Then
  1900.                                         tipo_modem(t).seq = tipo_modem(t).seq + 1
  1901.                                         seq_modem_vazio = tipo_modem(t).seq
  1902.                                         GoTo encontrado_tipo_modem_pop_vazio
  1903.                                     End If
  1904.  
  1905.                                 Next    'For t = 0 To UBound(tipo_modem)
  1906.  
  1907.                                 'SO SERA EXECUTADO SE NAO ACHAR
  1908. 'CRIA UM NOVO TIPO DE MODEM CASO NENHUM SEJA ENCONTRADO
  1909.                                tipo_modem(UBound(tipo_modem)).nome = modem_pop_plan
  1910.                                 tipo_modem(UBound(tipo_modem)).seq = 1
  1911.                                 seq_modem_vazio = 1
  1912.                                 ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
  1913.  
  1914.                                 'SO SERA EXECUTADO SE NAO ACHAR
  1915. encontrado_tipo_modem_pop_vazio:
  1916.  
  1917.                                 modem_pop_plan = modem_pop_plan & "." & mux(i) & "." & seq_modem_vazio
  1918.  
  1919.                             End If
  1920. 'CASO O MODEM SEJA FLEX OU AX4E1, A PORTA DO MODEM DO CLIENTE É A VARIAVEL 'slot_flex' E A PORTA DO LADO DO POP É PO1
  1921.                            If tipo_modem_pop_plan = "MOFL4E1" Or tipo_modem_pop_plan = "MOAX4E1" Then
  1922.  
  1923.                                 porta_modem_pop_cliente = slot_flex
  1924.                                 porta_modem_cliente_pop = "PO1"
  1925.  
  1926.                             Else
  1927. 'CASO CONTRARIO AMBAS AS PORTAS DO LADO DO CLIENTE E DO POP SÃO PORTAS OTICAS (PO1)
  1928.                                porta_modem_pop_cliente = "PO1"
  1929.                                 porta_modem_cliente_pop = "PO1"
  1930.  
  1931.  
  1932.                             End If
  1933. 'CASO NAO EXISTA UMA PORTA DE MODEM FLEX E A COLUNA J (PORTA DO LADO DO POP) NAO ESTEJA VAZIA,
  1934.                            If porta_flex = "" And Not IsEmpty(Range("J" & linha_plan).Value) And RemoveSpaces(Range("J" & linha_plan).Value) <> "" Then
  1935.  
  1936.                                 porta_pop_plan = Range("J" & linha_plan).Value
  1937. 'CASO EXISTA UMA PORTA FLEX, PEGA-SE O VALOR DELA
  1938.                            ElseIf porta_flex <> "" Then
  1939.  
  1940.                                 porta_pop_plan = porta_flex & "-" & slot_flex
  1941. 'CASO O MODEM SEJA CABO_POP, CRIA-SE A PORTA 'PE1'  E A PORTA 'PE1' para conversores
  1942.                            ElseIf tipo_modem_pop_plan = "CABO_POP" Then
  1943.  
  1944.                                 porta_pop_plan = "PE1"
  1945.                                
  1946.                             ElseIf tipo_modem_pop_plan = "CONV" Then
  1947.                                
  1948.                                 porta_pop_plan = "PE1"
  1949.                                    
  1950.                             Else
  1951.                            
  1952.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
  1953.                                 ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do não modem encontrada.")
  1954.                                vazia = 1
  1955.  
  1956.                             End If
  1957. 'CASO O MODEM DO CLIENTE NAO ESTEJA VAZIO, PEGA OS DADOS DELE
  1958.                            If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" Then
  1959.  
  1960.                                 modem_cliente_plan = Range("E" & linha_plan).Value
  1961.                                 tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
  1962.                                
  1963.                             Else
  1964.                            
  1965.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("E" & linha_plan).Address))
  1966.                                 ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("E" & linha_plan).Value, "Modem do cliente não encontrado.")
  1967.                                vazia = 1
  1968.      
  1969.  
  1970.                             End If
  1971. 'CASO O MODEM DO CLIENTE EXISTA E A COLUNA F NAO ESTEJA VAZIA, PEGA-SE OS DADOS DA PORTA DO CLIENTE DA COLUNA F
  1972.                            If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" And Not IsEmpty(Range("F" & linha_plan).Value) And RemoveSpaces(Range("F" & linha_plan).Value) <> "" Then
  1973.  
  1974.                                 porta_cli_plan = Range("F" & linha_plan).Value
  1975.  
  1976. 'CASO O MODEM SEJA CABO_CLI, CRIA-SE A PORTA 'P01' E A PORTA 'PE1' para conversores
  1977.                            ElseIf tipo_modem_cliente_plan = "CABO_CLI" Then
  1978.  
  1979.                                 porta_cli_plan = "PO1"
  1980.  
  1981.                             ElseIf tipo_modem_cliente_plan = "CONV" Then
  1982.                            
  1983.                                 porta_cli_plan = "PE1"
  1984.                            
  1985.                             Else
  1986.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
  1987.                                 ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do não modem encontrada.")
  1988.                                vazia = 1
  1989.      
  1990.                             End If
  1991.  
  1992. 'CASO A COLUNA N ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OPERADORA DELA
  1993.                            If Not IsEmpty(Range("N" & linha_plan).Value) And RemoveSpaces(Range("N" & linha_plan).Value) <> "" Then
  1994.  
  1995.                                 operadora_plan = Range("N" & linha_plan).Value
  1996.  
  1997.                             End If
  1998. 'CASO A COLUNA O ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OS DELA
  1999.                            If Not IsEmpty(Range("O" & linha_plan).Value) And RemoveSpaces(Range("O" & linha_plan).Value) <> "" Then
  2000.  
  2001.                                 os_plan = Range("O" & linha_plan).Value
  2002.  
  2003.                             End If
  2004.  
  2005. 'CASO A COLUNA B ESTEJA PREENCHIDA, PEGA-SE OS DADOS DO STATUS DO CIRCUITO DELA
  2006.                            If Not IsEmpty(Range("B" & linha_plan)) And RemoveSpaces(Range("B" & linha_plan).Value) <> "" Then
  2007.                            
  2008.                                 status_circuito = Range("B" & linha_plan).Value
  2009.                                
  2010.                            Else
  2011.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("B" & linha_plan).Address))
  2012.                                 ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("B" & linha_plan).Value, "Status do circuito não encontrado.")
  2013.                                vazia = 1
  2014.      
  2015.                            
  2016.                             End If
  2017. 'SELECIONA A PLANILHA CRIADA NO COMEÇO DO SCRIPT
  2018.                            Windows(nova).Activate
  2019. 'CALCULA A ULTIMA LINHA PREENCHIDA DELE
  2020.                            If WorksheetFunction.CountA(Cells) > 0 Then
  2021.                                 'Search for any entry, by searching backwards by Rows.
  2022.                                LastRow2 = Cells.Find(What:="*", After:=[A1], _
  2023.                                                       SearchOrder:=xlByRows, _
  2024.                                                       SearchDirection:=xlPrevious).Row
  2025.                             End If
  2026. 'VARIAVEIS UTLIZADAS PRA CONTROLE DE LOOP NA PLANILHA NOVA
  2027.                            If (LastRow2 = 0 Or LastRow2 = "") And rodada = 0 Then
  2028.  
  2029.                                 inicio_nova = 1
  2030.                                 rodada = 1
  2031.  
  2032.                             ElseIf rodada = 0 Then
  2033.  
  2034.                                 inicio_nova = LastRow2
  2035.                                 rodada = 1
  2036.  
  2037.                             End If
  2038. 'PREENCHE OS DADOS OBTIDOS NO SCRIPT E TRANSCREVE-OS PARA A NOVA PLANILHA
  2039.  
  2040.  
  2041. ' VALIDA SE EXISTEM PORTAS ORFAS COM O MESMO ENDEREÇO
  2042.  
  2043.  
  2044. If modem_cliente_plan = "" Then
  2045.  
  2046. Windows(arquivo).Activate
  2047.  
  2048.     porta_mod_cli = Range("F" & linha_plan).Value
  2049.     cor_porta_mod_cli = Range("F" & linha_plan).Font.Color
  2050.     end_mod_cli = Range("H" & linha_plan).Value
  2051.     end_mod_cli = RemoveSpaces(UCase(end_mod_cli))
  2052.    
  2053.    
  2054.     For Each celula_mod_cli In Range("C4:C" & LastRow)
  2055.    
  2056.         linha_mod_cli = celula_mod_cli.Row
  2057.        
  2058.         If (Range("F" & linha_mod_cli).Font.Color = cor_porta_mod_cli) And (end_mod_cli = RemoveSpaces(UCase(Range("H" & linha_mod_cli).Value))) And (linha_mod_cli <> linha_plan) Then
  2059.        
  2060.             modem_cliente_plan = Range("E" & linha_mod_cli).Value
  2061.             porta_cli_plan = porta_mod_cli
  2062.             tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
  2063.             Exit For
  2064.        
  2065.         End If
  2066.        
  2067.    
  2068.    
  2069.     Next 'For Each CELULA_MOD_CLI In Range("C4:C" & lastrow)
  2070.  
  2071. Windows(nova).Activate
  2072.  
  2073. End If
  2074.  
  2075.  
  2076.                             'If vazia = 0 Then
  2077.  
  2078.                                 Range("A" & LastRow2 + 1).Select
  2079.                                 ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=end2, SubAddress:=subend, TextToDisplay:=circuito_plan
  2080.                                 Range("B" & LastRow2 + 1).Value = pop_mux_plan
  2081.                                 Range("D" & LastRow2 + 1).Value = nome_mux_plan
  2082.                                 Range("C" & LastRow2 + 1).Value = tipo_mux_plan
  2083.                                 Range("E" & LastRow2 + 1).Value = slot_plan
  2084.                                 Range("F" & LastRow2 + 1).Value = placa_plan
  2085.                                 Range("G" & LastRow2 + 1).Value = porta_mux_plan
  2086.                                 Range("H" & LastRow2 + 1).Value = porta_pop_plan
  2087.                                 Range("I" & LastRow2 + 1).Value = modem_pop_plan
  2088.                                 Range("J" & LastRow2 + 1).Value = tipo_modem_pop_plan
  2089.                                 Range("K" & LastRow2 + 1).Value = porta_modem_pop_cliente
  2090.                                 Range("L" & LastRow2 + 1).Value = porta_modem_cliente_pop
  2091.                                 Range("M" & LastRow2 + 1).Value = modem_cliente_plan
  2092.                                 Range("O" & LastRow2 + 1).Value = tipo_modem_cliente_plan
  2093.                                 Range("N" & LastRow2 + 1).Value = porta_cli_plan
  2094.                                 Range("P" & LastRow2 + 1).Value = operadora_plan
  2095.                                 Range("Q" & LastRow2 + 1).Value = os_plan
  2096.                                 Range("R" & LastRow2 + 1).Value = status_circuito
  2097.    
  2098.    
  2099.     'RESETA TODAS AS VARIAVEIS UTILIZADAS NO SCRIPT
  2100.    
  2101.                                 circuito_plan = ""
  2102.                                 pop_mux_plan = ""
  2103.                                 nome_mux_plan = ""
  2104.                                 tipo_mux_plan = ""
  2105.                                 '                            slot_plan = ""
  2106.                                '                            placa_plan = ""
  2107.                               porta_mux_plan = ""
  2108.                                 porta_pop_plan = ""
  2109.                                 modem_pop_plan = ""
  2110.                                 tipo_modem_pop_plan = ""
  2111.                                 porta_modem_pop_cliente = ""
  2112.                                 porta_modem_cliente_pop = ""
  2113.                                 modem_cliente_plan = ""
  2114.                                 tipo_modem_cliente_plan = ""
  2115.                                 porta_modem_pop_cliente = ""
  2116.                                 porta_modem_cliente_pop = ""
  2117.                                 porta_cli_plan = ""
  2118.                                 operadora_plan = ""
  2119.                                 os_plan = ""
  2120.                                 status_circuito = ""
  2121.                                 subend = ""
  2122.    
  2123.                             'End If ' if vazia = 0 then
  2124.                                
  2125.                             vazia = 0
  2126.  
  2127.                             Windows(arquivo).Activate
  2128.  
  2129.                         End If
  2130.  
  2131.  
  2132.                     Next    'Each celula In Range(ciclo_pop(i))
  2133.  
  2134.                     ReDim modens(0)
  2135.                     ReDim tipo_modem(0)
  2136.  
  2137.                 Next    'For i = 0 To UBound(ciclo_pop)
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.             End If    '                If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  2147.            
  2148. 'AO FIM DE CADA ABA, VERIFICA SE HÁ A NECESSIDADE DE REORGANIZAR AS PORTAS DOS DM705
  2149.            If rodada <> 0 Then
  2150.  
  2151.                 Windows(nova).Activate
  2152.  
  2153.                 If WorksheetFunction.CountA(Cells) > 0 Then
  2154.                     'Search for any entry, by searching backwards by Rows.
  2155.                    LastRow3 = Cells.Find(What:="*", After:=[A1], _
  2156.                                           SearchOrder:=xlByRows, _
  2157.                                           SearchDirection:=xlPrevious).Row
  2158.                 End If
  2159.  
  2160.                 dm_on = 0
  2161. 'PEGA CADA CELULA DA COLUNA J QUE COMPREENDE UM RESULTADO DE UMA 'ABA'
  2162.                For Each celula_nova In Range("J" & inicio_nova & ":J" & LastRow3)
  2163.  
  2164.                     'On Error Resume Next
  2165. '
  2166.                    If WorksheetFunction.CountA(Cells) > 0 Then
  2167.                         'Search for any entry, by searching backwards by Rows.
  2168.                        LastRow4 = Cells.Find(What:="*", After:=[A1], _
  2169.                                               SearchOrder:=xlByRows, _
  2170.                                               SearchDirection:=xlPrevious).Row
  2171.                     End If
  2172.  
  2173.                     linha_nova = celula_nova.Row
  2174. 'CASO A PORTA DO MULTIPLEXADOR CONTENHA A LETRA 'P', NAO HÁ NADA A FAZER
  2175.                    If InStr(1, Range("G" & linha_nova).Value, "P") <> 0 Then
  2176.                         dm_on = 0
  2177.                     End If
  2178. 'SE O TIPO DE EQUIPAMENTO FOR DM705, PEGA A PORTA DO MODEM DO POP E O TIPO DELA. O FLAG DM_ON SIGNIFICA QUE FOI ENCONTRADO UM DM705
  2179. 'QUE PRECISA TER OS EQUIPAMENTOS ASSOCIADOS A ELE REARRANJADOS
  2180.                    If celula_nova.Value = "DM705" Then
  2181.                         dm_atual = Range("I" & linha_nova).Value
  2182.                         port_dm_atual = Range("H" & linha_nova).Value
  2183.                         dm_on = 1
  2184.                     End If
  2185. 'VERIFICA SE EXISTE ALGUMA VIRGULA NA PORTA DO MUX, EM CASO POSITIVO, SUBSTITUI-AS POR '.'
  2186.                    If InStr(1, Range("G" & linha_nova).Value, ",") <> 0 Then
  2187.                         Range("G" & linha_nova).Value = Replace(Range("G" & linha_nova).Value, ",", ".")
  2188. 'CASO NAO HAJA 'P' NA PORTA DO MUX, ASSOCIA-SE A LETRA 'P' A ELA
  2189.                        If InStr(1, Range("G" & linha_nova).Value, "P") = 0 Then
  2190.                             Range("G" & linha_nova).Value = "P" & Range("G" & linha_nova).Value
  2191.                         End If
  2192.                     End If
  2193. 'CASO EXISTAM 2 LETRAS 'PP' NO MUX, CORRIGE PARA 1 SÓ
  2194.                    If InStr(1, Range("G" & linha_nova).Value, "PP") <> 0 Then
  2195.  
  2196.                         Range("G" & linha_nova).Value = Replace(Range("G" & linha_nova).Value, "PP", "P")
  2197.  
  2198.                     End If
  2199. 'RETIRA-SE A LETRA QUE IDENTIFICA O SLOT DO DM705, CASO NAO EXISTA, ASSUME-SE A LETRA 'A'
  2200.                    If Not IsEmpty(Range("G" & linha_nova)) And RemoveSpaces(Range("G" & linha_nova).Value) <> "" Then
  2201.                         tt = Range("G" & linha_nova).Value
  2202.                         posicaoletra = InStr(1, tt, ".")
  2203.                         letra = Mid(tt, 1, posicaoletra - 1)
  2204.                     Else
  2205.  
  2206.                         letra = "A"
  2207.  
  2208.                     End If
  2209. 'REORGANIZA OS DADOS DO CIRCUITO PARA REFLETIR A REALIDADE DE UM DM705 - MAIS INFORMACOES COM O RONALDO DA ENGENHARIA
  2210.                    If (letra = "A" Or letra = "B" Or letra = "C" Or letra = "D" Or letra = "E" Or letra = "F" Or letra = "G" Or letra = "H") And dm_on = 1 Then
  2211.  
  2212.                         circuito_n = Range("A" & linha_nova).Value
  2213.                         pop_n = Range("B" & linha_nova).Value
  2214.                         porta_mux_n = Range("G" & linha_nova).Value
  2215.                         porta_modem_n = Range("H" & linha_nova).Value
  2216.                         nome_modem_pop_n = Range("I" & linha_nova).Value
  2217.                         tipo_modem_pop_n = Range("J" & linha_nova).Value
  2218.                         porta_modem_pop_cli_n = Range("K" & linha_nova).Value
  2219.                         porta_modem_cli_pop_n = Range("L" & linha_nova).Value
  2220.                         modem_cli_n = Range("M" & linha_nova).Value
  2221.                         porta_modem_cli_n = Range("N" & linha_nova).Value
  2222.                         tipo_modem_cli_n = Range("O" & linha_nova).Value
  2223.                         operadora_n = Range("P" & linha_nova).Value
  2224.                         os_n = Range("Q" & linha_nova).Value
  2225.                         'endereco_n = Range("A" & linha_nova).Hyperlinks(1).Address
  2226.                        status_circuito = Range("R" & linha_nova).Value
  2227.  
  2228.  
  2229.  
  2230.                         Range("A" & LastRow4 + 1).Value = circuito_n
  2231.                         Range("B" & LastRow4 + 1).Value = pop_n
  2232.                         Range("C" & LastRow4 + 1).Value = "DM705"
  2233.  
  2234.                         Range("D" & LastRow4 + 1).Value = dm_atual
  2235.                         Range("G" & LastRow4 + 1).Value = porta_mux_n
  2236.                         Range("H" & LastRow4 + 1).Value = porta_modem_n
  2237.                         Range("I" & LastRow4 + 1).Value = nome_modem_pop_n
  2238.                         Range("J" & LastRow4 + 1).Value = tipo_modem_pop_n
  2239.                         Range("K" & LastRow4 + 1).Value = porta_modem_pop_cli_n
  2240.                         Range("L" & LastRow4 + 1).Value = porta_modem_cli_pop_n
  2241.                         Range("M" & LastRow4 + 1).Value = modem_cli_n
  2242.                         Range("N" & LastRow4 + 1).Value = porta_modem_cli_n
  2243.                         Range("O" & LastRow4 + 1).Value = tipo_modem_cli_n
  2244.                         Range("P" & LastRow4 + 1).Value = operadora_n
  2245.                         Range("Q" & LastRow4 + 1).Value = os_n
  2246.                         subs_end = "'" & aba & "'!" & RemoveDolars((Range("R" & linha_nova).Value))
  2247.                         'ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & LastRow4 + 1), Address:=endereco_n, SubAddress:=subs_end, TextToDisplay:=Range("A" & linha_nova).Value
  2248.                        Range("R" & LastRow4 + 1).Value = status_circuito
  2249.  
  2250. 'RESETA AS VARIAVEIS
  2251.                        circuito_n = ""
  2252.                         pop_n = ""
  2253.                         porta_mux_n = ""
  2254.                         porta_modem_n = ""
  2255.                        nome_modem_pop_n = ""
  2256.                         tipo_modem_pop_n = ""
  2257.                         porta_modem_pop_cli_n = ""
  2258.                         porta_modem_cli_pop_n = ""
  2259.                         modem_cli_n = ""
  2260.                         porta_modem_cli_n = ""
  2261.                         tipo_modem_cli_n = ""
  2262.                         operadora_n = ""
  2263.                         os_n = ""
  2264.                         endereco_n = ""
  2265.                         status_circuito = ""
  2266.  
  2267.                         Rows(linha_nova & ":" & linha_nova).Select
  2268.                         Selection.Interior.ColorIndex = 3
  2269.  
  2270.  
  2271.  
  2272.                     End If
  2273.  
  2274.  
  2275.                 Next
  2276. 'APAGA AS LINHAS DESNECESSARIAS QUE FORAM REARRANJADAS PARA O DM705
  2277.                For bla = 1 To LastRow4
  2278.  
  2279.                     linha_apaga = bla
  2280.  
  2281.                     If Range("A" & bla).Interior.ColorIndex = 3 Then
  2282.  
  2283.                         Rows(linha_apaga & ":" & linha_apaga).Select
  2284.                         Selection.Delete Shift:=xlUp
  2285.  
  2286.                         bla = bla - 1
  2287.  
  2288.                         If bla < 0 Then
  2289.                             bla = 1
  2290.                         End If
  2291.  
  2292.                     End If
  2293.  
  2294.  
  2295.                 Next
  2296.  
  2297. 'RETORNA AO ARQUIVO ORIGINAL
  2298.                Windows(arquivo).Activate
  2299.  
  2300.  
  2301.             End If    'If rodada <> 0 Then
  2302.  
  2303.             rodada = 0
  2304.  
  2305.  
  2306.         Next    '            For Each sheet In ActiveWorkbook.Worksheets
  2307.        
  2308.         Windows(arquivo).Activate
  2309.        
  2310.        
  2311.        
  2312.        
  2313.    'FECHA O ARQUIVO DE FACILIDADES
  2314.  
  2315.         Windows(arquivo).Close False
  2316.  
  2317.     Next    '        For sasa = LBound(Filename) To UBound(Filename)    ' FOR abre arquivos
  2318.  
  2319. 'ATIVA A PLANILHA NOVA
  2320.    Windows(nova).Activate
  2321. 'CRIA UMA NOVA COLUNA PARA INSERÇÃO DAS HIERARQUIAS ENTRE MODENS DO CLIENTE E DO POP(H) E DA HIERARQUIA ENTRE O MODEM DO POP E O MUX (M)
  2322.    Range("H:H").Select
  2323.  
  2324.     Selection.Insert Shift:=xlToRight
  2325.  
  2326.     Range("M:M").Select
  2327.  
  2328.     Selection.Insert Shift:=xlToRight
  2329.  
  2330.     If WorksheetFunction.CountA(Cells) > 0 Then
  2331.         'Search for any entry, by searching backwards by Rows.
  2332.        LastRow5 = Cells.Find(What:="*", After:=[A1], _
  2333.                               SearchOrder:=xlByRows, _
  2334.                               SearchDirection:=xlPrevious).Row
  2335.     End If
  2336.     'SELECIONA O ARQUIVO 'HIERARQUIAS.XLSX'
  2337.    Windows("hierarquias.xlsx").Activate
  2338.   'PEGA A QUANTIDADE DE HIERAQUIAS EXISTENTES NO ARQUIVO DE HIERARQUIAS
  2339.    
  2340.         If WorksheetFunction.CountA(Cells) > 0 Then
  2341.         'Search for any entry, by searching backwards by Rows.
  2342.        LastRow15 = Cells.Find(What:="*", After:=[A1], _
  2343.                               SearchOrder:=xlByRows, _
  2344.                               SearchDirection:=xlPrevious).Row
  2345.     End If
  2346. '   RETORNA A PLANILHA NOVA
  2347.    Windows(nova).Activate
  2348.  
  2349. 'VALIDA CADA UMA DAS LINHAS DA PLANILHA NOVA
  2350.  
  2351.     For Each celula In Range("A1:A" & LastRow5)
  2352.  
  2353.         linha = celula.Row
  2354. 'PEGA OS DADOS DO POP, MUX E EQUIPAMENTO DO CLIENTE
  2355.        equip_pop = Range("K" & linha).Value
  2356.         equip_mux = Range("C" & linha).Value
  2357.         equip_cliente = Range("Q" & linha).Value
  2358.         placa = Range("F" & linha).Value
  2359.         placa = Mid(placa, 1, InStr(1, placa, ".") - 1)
  2360.  
  2361.         Windows("hierarquias.xlsx").Activate
  2362.  
  2363. 'RETORNA A PLANILHA DE HIERARQUIAS PARA COMPARACAO
  2364.        hierarquia1 = ""
  2365.         hierarquia2 = ""
  2366.  
  2367.         For Each celula2 In Range("A1:A" & LastRow15)
  2368. 'COMPARA OS DADOS DE HIERARQUIA ENTRE OS EQUIPAMENTOS DO CLIENTE E POP E SIMULTANEAMENTE COMPARA A HIERARQUIA ENTRE OS EQUIPAMENTOS DO MUX E DO POP
  2369.            linha2 = celula2.Row
  2370.  
  2371.             compara1 = Range("B" & linha2).Value
  2372.             compara2 = Range("D" & linha2).Value
  2373.             compara3 = Range("F" & linha2).Value
  2374.             compara4 = Range("A" & linha2).Value
  2375.  
  2376.             If equip_mux = compara1 And equip_pop = compara2 And equip_cliente = compara3 And placa = compara4 Then
  2377.  
  2378.                 hierarquia1 = Range("C" & linha2).Value
  2379.                 hierarquia2 = Range("E" & linha2).Value
  2380. 'QUANTO ENCONTRA TUDO, RETORNA
  2381.                GoTo encontrou_hierarq
  2382.  
  2383.             End If
  2384.  
  2385.         Next
  2386.  
  2387. encontrou_hierarq:
  2388.  
  2389.  
  2390.         Windows(nova).Activate
  2391. 'ESCREVE OS VALORES DAS HIERARQUIAS NOS SEUS DEVIDOS LOCAIS
  2392.        Range("H" & linha).Value = hierarquia1
  2393.         Range("M" & linha).Value = hierarquia2
  2394.        
  2395. '        If RemoveSpaces(hierarquia1) = "" Or RemoveSpaces(hierarquia2) = "" Then
  2396.        
  2397. '            'retorno_erro = 'erro(plan_erro, nova, "", "", "", "Erro - Tipo de hierarquia inexistente : " & equip_mux & "," & equip_pop & "," & equip_cliente)
  2398. '            Range(linha & ":" & linha).Select
  2399. '            Selection.Clear
  2400.    
  2401.        
  2402. '        End If
  2403.        
  2404.        
  2405.  
  2406.  
  2407.  
  2408.     Next
  2409.  
  2410.     Windows(nova).Activate
  2411. 'CRIA DUAS COLUNAS NOVAS PARA INSERIR A FRAÇÃO DO TRIBUTARIO QUE É UTILIZADO ENTRE O CLIENTE E O MODEM DO POP E ENTRE O MODEM DO POP E O MUX
  2412.    Range("H:H").Select
  2413.  
  2414.     Selection.Insert Shift:=xlToRight
  2415.  
  2416.     Range("N:N").Select
  2417.  
  2418.     Selection.Insert Shift:=xlToRight
  2419.  
  2420.     If WorksheetFunction.CountA(Cells) > 0 Then
  2421.         'Search for any entry, by searching backwards by Rows.
  2422.        LastRow6 = Cells.Find(What:="*", After:=[A1], _
  2423.                               SearchOrder:=xlByRows, _
  2424.                               SearchDirection:=xlPrevious).Row
  2425.     End If
  2426.  
  2427.     For Each celula In Range("A1:A" & LastRow6)
  2428.  
  2429.         linha = celula.Row
  2430.        
  2431. '        equipamento_teste = Range("D" & linha).Value
  2432. '
  2433. '        If InStr(1, equipamento_teste, "203") <> 0 Then
  2434. '
  2435. '            huahsuahsas1 = 0
  2436. '
  2437. '        End If
  2438. 'PEGA OS DADOS DAS PORTAS PARA COMPARAR E ENCONTRAR O TRIBUTARIO
  2439.        porta_mux = Range("G" & linha).Value
  2440.         porta_pop = Range("J" & linha).Value
  2441.         porta_pop_cli = Range("M" & linha).Value
  2442.         porta_cli_pop = Range("P" & linha).Value
  2443.         porta_cli = Range("R" & linha).Value
  2444. 'PEGA OS TIPOS DOS EQUIPAMENTOS (MUX, EQUIP DO LADO DO POP E EQUIP DO LADO DO CLIENTE)
  2445.        tipo_mux = Range("C" & linha).Value
  2446.         tipo_pop = Range("L" & linha).Value
  2447.         tipo_cli = Range("S" & linha).Value
  2448. 'PARA TODO DM705 A FRACAO É IGUAL A PORTA, P1 = FRACAO 1, P2 = FRACAO 2, ETC
  2449.        If InStr(1, tipo_mux, "DM705") Then
  2450.  
  2451.             fracao_1 = Mid(porta_cli, InStr(1, porta_cli, "P") + 1, Len(porta_cli))
  2452.             fracao_2 = Mid(porta_cli, InStr(1, porta_cli, "P") + 1, Len(porta_cli))
  2453. 'PARA TODOS OS OUTROS MUX A FRACAO É 1
  2454.        Else
  2455.  
  2456.             fracao_1 = "1"
  2457.  
  2458.         End If
  2459.        
  2460. 'PARA OS MODENS ASGA 2 E 4E1s, DM4E1S E DM16E1, A REGRA É : A FRACAO É IGUAL A PORTA, P1 = FRACAO 1, P2 = FRACAO 2, ETC
  2461.  
  2462.         If tipo_cli = "MOASGA2E1" Or tipo_cli = "MOASGA4E1" Or tipo_cli = "DM4E1S" Or tipo_cli = "DM16E1" Then
  2463.  
  2464.             fracao_2 = Mid(porta_cli, InStr(1, porta_cli, "P") + 1, Len(porta_cli))
  2465.  
  2466.         End If
  2467. 'PARA OS MODEMS MHMUSIC200 E MHLECAR OU DM706 A FRACAO É 1
  2468.        If tipo_cli = "MHMUSIC200" Or tipo_cli = "MHLECAR" Or tipo_cli = "DM706" Then
  2469.  
  2470.             fracao_2 = "1"
  2471.  
  2472.         End If
  2473. 'PARA OS CABOS_CLI A FRACAO É 1
  2474.        If fracao_2 = "" And tipo_cli = "CABO_CLI" Then
  2475.  
  2476.             fracao_2 = 1
  2477.  
  2478.         End If
  2479. 'PARA OS CONV A FRACAO É 1
  2480.        If fracao_2 = "" And tipo_cli = "CONV" Then
  2481.  
  2482.             fracao_2 = 1
  2483.  
  2484.         End If
  2485. 'SE A FRACAO FOR O1 (RESULTANTE DE PORTAS PO1) A FRACA É 1
  2486.        If fracao_1 = "O1" Then
  2487.  
  2488.             fracao_1 = "1"
  2489.  
  2490.         End If
  2491. 'SE A FRACAO FOR O1 (RESULTANTE DE PORTAS PO1) A FRACA É 1
  2492.        If fracao_2 = "O1" Then
  2493.  
  2494.             fracao_2 = "1"
  2495.  
  2496.         End If
  2497.  
  2498. 'ESCREVE OS VALORES DAS FRACOES GERADAS NAS NOVAS COLUNAS N E H
  2499.        Range("H" & linha).Value = fracao_1
  2500.         Range("N" & linha).Value = fracao_2
  2501.  
  2502.         fracao_1 = ""
  2503.         fracao_2 = ""
  2504. 'PARA OS DM705 OS DADOS DE SLOT E PLACA SAO REPLICADOS COM O VALOR DA PORTA E A PORTA DO MUX FICA P1.1
  2505.        If tipo_mux = "DM705" Then
  2506.  
  2507.             porta_mux = Mid(porta_mux, 1, InStr(1, porta_mux, ".") - 1)
  2508.             Range("E" & linha).Value = porta_mux
  2509.             Range("F" & linha).Value = porta_mux
  2510.             Range("G" & linha).Value = "P1.1"
  2511.  
  2512.         End If
  2513.  
  2514.  
  2515.     Next
  2516.  
  2517.  
  2518. 'ORGANIZA OS DADOS E GERA NOME PARA CADA COLUNA
  2519.    Range("1:1").Select
  2520.  
  2521.     Selection.Insert Shift:=xlDown
  2522.  
  2523.     Range("A1").Value = "Desig"
  2524.     Range("B1").Value = "POP"
  2525.     Range("C1").Value = "Tipo EQUIP"
  2526.     Range("D1").Value = "Nome Equip"
  2527.     Range("E1").Value = "SLOT"
  2528.     Range("F1").Value = "PLACA"
  2529.     Range("G1").Value = "Porta Placa"
  2530.     Range("H1").Value = "Fração"
  2531.     Range("I1").Value = "Hierarquia"
  2532.     Range("J1").Value = "Porta Modem pop"
  2533.     Range("K1").Value = "Modem Pop"
  2534.     Range("L1").Value = "Tipo Modem"
  2535.     Range("M1").Value = "Porta Otica"
  2536.     Range("N1").Value = "Fração"
  2537.     Range("O1").Value = "Hierarquia"
  2538.     Range("P1").Value = "Porta Otica"
  2539.     Range("Q1").Value = "Modem Cliente"
  2540.     Range("R1").Value = "Porta Modem Cliente"
  2541.     Range("S1").Value = "Tipo Modem Cliente"
  2542.     Range("T1").Value = "Operadora"
  2543.     Range("U1").Value = "OS"
  2544.     Range("V1").Value = "LINK"
  2545.    
  2546.    
  2547. 'APAGA OS REGISTROS VAZIOS
  2548.  
  2549.     If WorksheetFunction.CountA(Cells) > 0 Then
  2550.         'Search for any entry, by searching backwards by Rows.
  2551.        lastrow99 = Cells.Find(What:="*", After:=[A1], _
  2552.                               SearchOrder:=xlByRows, _
  2553.                               SearchDirection:=xlPrevious).Row
  2554.     End If
  2555.    
  2556.    
  2557. For i = lastrow99 To 1 Step -1
  2558.  
  2559.     If (Range("A" & i).Value = "") Or (IsEmpty(Range("A" & i)) = True) Then
  2560.    
  2561.         Range(i & ":" & i).EntireRow.Delete
  2562.            
  2563.     End If
  2564.  
  2565.  
  2566. Next i
  2567.  
  2568. 'VOLTA A ATUALIZAR A TELA
  2569.  
  2570.     Windows("operadoras.xlsx").Close False
  2571.    
  2572.     Windows("hierarquias.xlsx").Close False
  2573.    
  2574.     'Application.ScreenUpdating = True
  2575.    
  2576.     ultimamilha = nova
  2577.  
  2578. End Function
  2579.  
  2580.  
  2581. 'FUNCAO PARA VERIFICAR SE A COR DA CELULA NAO É AUTOMATICA (0)
  2582. Public Function checa_cor(linha As Integer, coluna As Integer)
  2583.  
  2584.     If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
  2585.         checa_cor = 0
  2586.  
  2587.     Else
  2588.  
  2589.         checa_cor = 1
  2590.  
  2591.     End If    'If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
  2592.  
  2593. End Function
  2594.  
  2595. 'FUNCAO PARA PROCURAR A SIGLA DO POP NO BANCO DE DADOS MYSQL
  2596. Public Function acha_sigla_pop(ByVal nome_pop As String) As String
  2597.  
  2598.  
  2599.     rs.Open "select sigla_pop from pop  where nome_pop = '" & nome_pop & "'"
  2600.    
  2601.     acha_sigla_pop = rs!sigla_pop
  2602.  
  2603.     rs.Close
  2604.  
  2605.  
  2606. End Function
  2607. 'FUNCAO PARA PROCURAR O TIPO DE EQUIPAMENTO NO BANCO DE DADOS MYSQL
  2608. Public Function acha_tipo_equip(ByVal nome_mux As String) As String
  2609.  
  2610.  
  2611.     rs.Open "select t.nome_tipo_equip from mux m join tipo_equip t on m.id_tipo_equip = t.id_tipo_equip where m.nome_mux = '" & nome_mux & "'"
  2612.  
  2613.     If rs.RecordCount = 0 Then
  2614.         acha_tipo_equip = 99
  2615.     Else
  2616.  
  2617.         acha_tipo_equip = rs!nome_tipo_equip
  2618.  
  2619.     End If
  2620.  
  2621.  
  2622.     rs.Close
  2623.  
  2624.  
  2625. End Function
  2626. 'FUNCAO PARA REMOVER O SIMBOLO DE DOLAR ('$') DA CELULA
  2627. Public Function RemoveDolars(strInput As String)
  2628. ' Removes all spaces from a string of text
  2629. Test:
  2630.     If InStr(strInput, "$") = 0 Then
  2631.         RemoveDolars = strInput
  2632.     Else
  2633.         strInput = Left(strInput, InStr(strInput, "$") - 1) _
  2634.                    & Right(strInput, Len(strInput) - InStr(strInput, "$"))
  2635.         GoTo Test
  2636.     End If
  2637. End Function
  2638. 'FUBNCAO PARA CONTAR A QUANTIDADE DE VEZES QUE UM CARACTER APARECE EM UMA DETERMINADA STRING
  2639. Function countSeparators(ByVal myString As String, ByVal mySeparator As String) As Integer
  2640.     countSeparators = UBound(Split(myString, mySeparator))
  2641. End Function
  2642.  
  2643. 'FUNCAO PARA IDENTIFICAR QUAL É A PONTA DO CLIENTE EM UMA DESIGNACAO
  2644.  
  2645. Public Function detecta(ByVal circuito As String, ByVal nova As String, ByVal mux As String) As String
  2646.  
  2647.  
  2648.     Windows("operadoras.xlsx").Activate
  2649.  
  2650.     If WorksheetFunction.CountA(Cells) > 0 Then
  2651.         'Search for any entry, by searching backwards by Rows.
  2652.        LastRow10 = Cells.Find(What:="*", After:=[A1], _
  2653.                                SearchOrder:=xlByRows, _
  2654.                                SearchDirection:=xlPrevious).Row
  2655.     End If
  2656.  
  2657.     On Error GoTo achou_operadora
  2658.  
  2659.     circuito = LTrim(RTrim(circuito))
  2660.     circuito = Replace(circuito, "  ", " ")
  2661.  
  2662.     separa_1 = Mid(circuito, 1, InStr(1, circuito, " ") - 1)
  2663.  
  2664.     separa_2 = Mid(circuito, InStr(1, circuito, " ") + 1, Len(circuito))
  2665.  
  2666.     separa_3 = Mid(separa_2, 1, InStr(1, separa_2, " ") - 1)
  2667.  
  2668.     lado_a = Mid(separa_1, 4, Len(separa_1))
  2669.  
  2670.     lado_b = Mid(separa_3, 4, Len(separa_3))
  2671.  
  2672.     lado_a = RTrim(LTrim(lado_a))
  2673.     lado_b = RTrim(LTrim(lado_b))
  2674.  
  2675.  
  2676.  
  2677.     For Each celula_op In Range("A1:A" & LastRow10)
  2678.  
  2679.         If celula_op.Value = lado_a Then
  2680.  
  2681.             sigla_operadora = lado_b
  2682.             GoTo achou_operadora
  2683.  
  2684.         End If
  2685.  
  2686.         If celula_op.Value = lado_b Then
  2687.  
  2688.             sigla_operadora = lado_a
  2689.             GoTo achou_operadora
  2690.  
  2691.         End If
  2692.  
  2693.  
  2694.  
  2695.     Next
  2696.  
  2697.  
  2698.     If InStr(1, lado_a, mux) <> 0 Then
  2699.  
  2700.         Range("A" & LastRow10 + 1).Value = lado_a
  2701.         sigla_operadora = lado_b
  2702.  
  2703.     End If
  2704.  
  2705.     If InStr(1, lado_b, mux) <> 0 Then
  2706.  
  2707.         Range("A" & LastRow10 + 1).Value = lado_b
  2708.         sigla_operadora = lado_a
  2709.  
  2710.     End If
  2711.  
  2712.  
  2713. achou_operadora:
  2714.  
  2715.  
  2716.     Windows(nova).Activate
  2717.  
  2718.     detecta = sigla_operadora
  2719.  
  2720. End Function
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726. Function ConvertToLetter(ByVal iCol As Integer) As String
  2727.  
  2728.     If iCol > 26 Then
  2729.         ConvertToLetter = Chr(Int((iCol - 1) / 26) + 64) & Chr(((iCol - 1) Mod 26) + 65)
  2730.     Else
  2731.         ConvertToLetter = Chr(iCol + 64)
  2732.     End If
  2733. End Function
  2734.  
  2735.  
  2736. Public Function primeiramilha(ByRef path As String) As String
  2737.  
  2738.     Set rs = New ADODB.Recordset
  2739.  
  2740.     ConnectDB
  2741.  
  2742.     rs.ActiveConnection = conexao
  2743.     rs.LockType = adLockOptimistic
  2744.     rs.CursorLocation = adUseClient
  2745.     rs.CursorType = adOpenDynamic
  2746.  
  2747.  
  2748.     Dim sheet As Worksheet
  2749.     Dim celula, celula1 As Range
  2750.     Dim LastRow As Long
  2751.  
  2752.     Dim Filter As String
  2753.     Dim FilterIndex As Integer
  2754.     Dim Filename As Variant
  2755.     Dim remove As String
  2756.     Dim posicao As String
  2757.  
  2758.  
  2759.     seq_placa = 1
  2760.     id_sheet = 1
  2761.     nome_pop = ""
  2762.  
  2763. '   Application.ScreenUpdating = False
  2764.  
  2765. 'With Application.FileDialog(msoFileDialogFolderPicker)
  2766. '    .Show
  2767. '    Path = .SelectedItems(1)
  2768. 'End With
  2769.  
  2770. 'path = "C:\Users\ljunqueira\Documents\Sicop\teste"
  2771. Filename = ListaArquivos(path)
  2772.  
  2773. If Not IsArray(Filename) Then
  2774.     MsgBox "Nenhum arquivo selecionado."
  2775.     Exit Function
  2776. End If
  2777.  
  2778.     principal = ActiveWorkbook.Name
  2779.     Workbooks.Add
  2780.     ActiveWorkbook.Activate
  2781.     nova = ActiveWorkbook.Name
  2782.     'Workbooks.Add
  2783.    'ActiveWorkbook.Activate
  2784.    'erros = ActiveWorkbook.Name
  2785.  
  2786.  
  2787.     ' Open Files
  2788. For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
  2789.    If InStr(1, UCase(Filename(sasa)), "XLS") <> 0 Then
  2790.    
  2791.         msg = msg & Filename(sasa) & vbCrLf ' This can be removed
  2792.        
  2793.         If InStr(1, Filename(sasa), "?") <> 0 Then
  2794.        
  2795.             Filename(sasa) = Replace(Filename(sasa), "?", " ")
  2796.        
  2797.         End If
  2798.        
  2799.         Workbooks.Open Filename(sasa), False
  2800.        
  2801.         arquivo = ActiveWorkbook.Name
  2802.         Windows(arquivo).Activate
  2803.  
  2804.         For Each sheet In ActiveWorkbook.Worksheets
  2805.        
  2806.  
  2807.             If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  2808.  
  2809.                 sheet.Select
  2810.                 aba = sheet.Name
  2811.  
  2812.                 If WorksheetFunction.CountA(Cells) > 0 Then
  2813.                     'Search for any entry, by searching backwards by Rows.
  2814.                    LastRow = Cells.Find(What:="*", After:=[A1], _
  2815.                                          SearchOrder:=xlByRows, _
  2816.                                          SearchDirection:=xlPrevious).Row
  2817.                 End If
  2818.  
  2819.                 If WorksheetFunction.CountA(Cells) > 0 Then
  2820.                     'Search for any entry, by searching backwards by Columns.
  2821.                    LastColumn = Cells.Find(What:="*", After:=[A1], _
  2822.                                             SearchOrder:=xlByColumns, _
  2823.                                             SearchDirection:=xlPrevious).Column
  2824.                 End If
  2825.  
  2826.                 For Each celula In Range("C3:C" & LastRow)
  2827.  
  2828.                     linha = celula.Row
  2829.  
  2830.                     If celula.Interior.ColorIndex = 1 And preta = 0 Then
  2831.  
  2832.                         For Each celula2 In Range("E" & linha & ":" & ConvertToLetter(LastColumn) & linha)
  2833.  
  2834.  
  2835.                             If UCase(RemoveSpaces(celula2.Value)) = "FILA" Then
  2836.  
  2837.                                 fila_col = ConvertToLetter(celula2.Column)
  2838.                                 GoTo Achou
  2839.  
  2840.                             End If    'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
  2841.  
  2842.                             If UCase(RemoveSpaces(celula2.Value)) = "DID" Then
  2843.  
  2844.                                 did_col = ConvertToLetter(celula2.Column)
  2845.                                 GoTo Achou
  2846.  
  2847.                             End If    'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
  2848.  
  2849.                             If UCase(RemoveSpaces(celula2.Value)) = "RÉGUA" Then
  2850.  
  2851.                                 regua_col = ConvertToLetter(celula2.Column)
  2852.                                 GoTo Achou
  2853.  
  2854.                             End If    'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
  2855.  
  2856.                             If UCase(RemoveSpaces(celula2.Value)) = "POSIÇÃO" Then
  2857.  
  2858.                                 posicao_col = ConvertToLetter(celula2.Column)
  2859.  
  2860.                             End If    'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
  2861. Achou:
  2862.                             If fila_col <> "" And did_col <> "" And regua_col <> "" And posicao_col <> "" Then
  2863.                                 Exit For
  2864.                             End If
  2865.  
  2866.                             porta_col = "H"
  2867.  
  2868.                         Next    'For Each celula In Range("A" & linha & ":" & LastColumn & linha)
  2869.  
  2870.                         preta = 1
  2871.  
  2872.                         nome_mux = Range("C" & linha).Value
  2873.                         tipo_mux = Range("G" & linha).Value
  2874.                         If tipo_mux = "" Then
  2875.                             tipo_mux = Range("F" & linha).Value
  2876.                         End If
  2877.                         If tipo_mux = "" Then
  2878.                             tipo_mux = Range("H" & linha).Value
  2879.                         End If
  2880.                         endereco = Range("E" & linha).Value
  2881.                        
  2882.                         If nome_pop = "" Then
  2883.                        
  2884.                             nome_pop = Range("E3").Value
  2885.                             sigla_pop = Range("C3").Value
  2886.                        
  2887.                         End If
  2888.                        
  2889.                        
  2890.                     Else
  2891.  
  2892.                         If Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" Then
  2893.  
  2894.                             placa = Range("F" & linha).Value
  2895.                             placa = UCase(RemoveSpaces(placa))
  2896.                            ' sigla_pop = acha_sigla(nome_mux)
  2897.                            placa = placa & "." & sigla_pop & "." & seq_placa
  2898.                             seq_placa = seq_placa + 1
  2899.  
  2900.  
  2901.                         End If    '                        If Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" Then
  2902.  
  2903.  
  2904.                         If Not IsEmpty(Range("G" & linha).Value) And RemoveSpaces(Range("G" & linha).Value) <> "" Then
  2905.  
  2906.                             slot = Range("G" & linha).Value
  2907.  
  2908.                         End If    '                        If Not IsEmpty(Range("G" & linha).Value) And RemoveSpaces(Range("G" & linha).Value) <> "" Then
  2909.  
  2910.                         If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("H" & linha).Value) And RemoveSpaces(Range("H" & linha).Value) <> "" Then
  2911.  
  2912.  
  2913.                             If UCase(RemoveSpaces(Range("H2").Value)) = "FILA" Then
  2914.  
  2915.                                 porta_col = "G"
  2916.                                 fila_col = "H"
  2917.                                 did_col = "I"
  2918.                                 regua_col = "J"
  2919.                                 posicao_col = "K"
  2920.  
  2921.                             End If
  2922.  
  2923.                             If UCase(RemoveSpaces(Range("I2").Value)) = "FILA" Then
  2924.  
  2925.                                 porta_col = "H"
  2926.                                 fila_col = "I"
  2927.                                 did_col = "J"
  2928.                                 regua_col = "K"
  2929.                                 posicao_col = "L"
  2930.  
  2931.                             End If
  2932.                            
  2933.                             If fila_col = "" Then
  2934.                            
  2935.                                 ''retorno_erro = 'erro(erros, arquivo, "", "", "", "Erro - Arquivo não formatado  : " & arquivo)
  2936.                                
  2937.                                 GoTo proximo_col
  2938.                                
  2939.                             End If
  2940.  
  2941.                             circuito = Range("C" & linha).Value
  2942.                             porta = Range(porta_col & linha).Value
  2943.                            
  2944.                             If Not IsEmpty(Range(fila_col & linha)) And RemoveSpaces(Range(fila_col & linha).Value) <> "" Then
  2945.                                 fila = "'" & Range(fila_col & linha).Value
  2946.                             Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2947.                                fila = "-"
  2948.                             End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2949.  
  2950.                             If Not IsEmpty(Range(did_col & linha)) And RemoveSpaces(Range(did_col & linha).Value) <> "" Then
  2951.                                 did = "'" & Range(did_col & linha).Value
  2952.                             Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2953.                                did = "-"
  2954.                             End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2955.  
  2956.                             If Not IsEmpty(Range(regua_col & linha)) And RemoveSpaces(Range(regua_col & linha).Value) <> "" Then
  2957.                                 regua = "'" & Range(regua_col & linha).Value
  2958.                             Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2959.                                regua = "-"
  2960.                             End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2961.  
  2962.                             If Not IsEmpty(Range(posicao_col & linha)) And RemoveSpaces(Range(posicao_col & linha).Value) <> "" Then
  2963.                                 posicao = "'" & Range(posicao_col & linha).Value
  2964.                             Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2965.                                posicao = "-"
  2966.                             End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
  2967.                            
  2968.                            
  2969.                            
  2970.                            
  2971.                            
  2972.                            
  2973.  
  2974.  
  2975.  
  2976.  
  2977.                             Windows(nova).Activate
  2978.  
  2979.                             If WorksheetFunction.CountA(Cells) > 0 Then
  2980.                                 'Search for any entry, by searching backwards by Rows.
  2981.                                LastRow2 = Cells.Find(What:="*", After:=[A1], _
  2982.                                                       SearchOrder:=xlByRows, _
  2983.                                                       SearchDirection:=xlPrevious).Row
  2984.                             End If
  2985.  
  2986.                             Range("A" & LastRow2 + 1).Value = id_sheet
  2987.                             id_sheet = id_sheet + 1
  2988.                             Range("B" & LastRow2 + 1).Value = sigla_pop
  2989.                             Range("C" & LastRow2 + 1).Value = endereco
  2990.                             Range("D" & LastRow2 + 1).Value = nome_mux
  2991.                             Range("E" & LastRow2 + 1).Value = tipo_mux
  2992.                             Range("F" & LastRow2 + 1).Value = slot
  2993.                             Range("G" & LastRow2 + 1).Value = placa
  2994.                             Range("H" & LastRow2 + 1).Value = porta
  2995.                             Range("I" & LastRow2 + 1).Value = fila
  2996.                             Range("J" & LastRow2 + 1).Value = did
  2997.                             Range("K" & LastRow2 + 1).Value = regua
  2998.                             Range("L" & LastRow2 + 1).Value = posicao
  2999.                             Range("M" & LastRow2 + 1).Value = circuito
  3000.                             Range("N" & LastRow2 + 1).Value = arquivo
  3001.  
  3002.  
  3003.  
  3004.                             Windows(arquivo).Activate
  3005.  
  3006.                             porta = ""
  3007.                             fila = ""
  3008.                             did = ""
  3009.                             regua = ""
  3010.                             posicao = ""
  3011.                             circuito = ""
  3012.  
  3013.                         End If    '                        If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces(Range("C" & linha).Value) <> "" Then
  3014.  
  3015.  
  3016.  
  3017.                     End If
  3018.  
  3019. proximo_col:
  3020.                 Next    '                    For Each celula In Range("A3:A" & LastRow)
  3021.  
  3022.  
  3023.             End If    '                If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  3024.  
  3025.             preta = 0
  3026.             fila_col = ""
  3027.             did_col = ""
  3028.             regua_col = ""
  3029.             posicao_col = ""
  3030.             nome_pop = ""
  3031.  
  3032.         Next    '            For Each sheet In ActiveWorkbook.Worksheets
  3033.  
  3034.         Windows(arquivo).Close False
  3035.     End If
  3036. Next    '        For sasa = LBound(Filename) To UBound(Filename)    ' FOR abre arquivos
  3037.  
  3038.  
  3039.     Application.ScreenUpdating = True
  3040.    
  3041.     primeiramilha = nova
  3042.  
  3043. End Function
  3044.  
  3045.  
  3046.  
  3047.  
  3048.  
  3049. Public Function acha_sigla(ByVal nome_mux As String) As String
  3050.  
  3051.     rs.Open "select p.sigla_pop from mux m join pop p on m.id_pop = p.id_pop where m.nome_mux = '" & nome_mux & "'"
  3052.  
  3053.     acha_sigla = rs!sigla_pop
  3054.  
  3055.     rs.Close
  3056.  
  3057. End Function
  3058.  
  3059. Public Function acha_nome_pop(ByVal nome_mux As String) As String
  3060.  
  3061.     rs.Open "select p.nome_pop from mux m join pop p on m.id_pop = p.id_pop where m.nome_mux = '" & nome_mux & "'"
  3062.  
  3063.     acha_nome_pop = rs!nome_pop
  3064.  
  3065.     rs.Close
  3066.  
  3067. End Function
  3068.  
  3069.  
  3070.  
  3071. Public Function ListaArquivos(ByVal Caminho As String) As String()
  3072.  
  3073.     Dim FSO As New FileSystemObject
  3074.     Dim result() As String
  3075.     Dim result2 As Variant
  3076.     Dim Pasta As Folder
  3077.     Dim SubPasta As Folder
  3078.     Dim arquivo As File
  3079.     Dim Indice As Long
  3080.     Dim s1 As String
  3081.  
  3082.  
  3083.     ReDim result(0) As String
  3084.     If FSO.FolderExists(Caminho) Then
  3085.         Set Pasta = FSO.GetFolder(Caminho)
  3086.  
  3087.         For Each arquivo In Pasta.Files
  3088.             If arquivo.Type Like "*Planilha*" Then
  3089.                 Indice = IIf(result(0) = "", 0, Indice + 1)
  3090.                 ReDim Preserve result(Indice) As String
  3091.                
  3092.                 If InStr(1, arquivo.path, " ") <> 0 Then
  3093.                
  3094.                     caminho_arquivo = Replace(arquivo.path, " ", "?")
  3095.                    
  3096.                 Else
  3097.                
  3098.                     caminho_arquivo = arquivo.path
  3099.                
  3100.                 End If
  3101.                
  3102.                 result(Indice) = caminho_arquivo
  3103.             End If
  3104.         Next
  3105.        
  3106.         For Each SubPasta In Pasta.SubFolders
  3107.             result2 = ListaArquivos(SubPasta.path)
  3108.             s1 = Join(result, " ") + " "
  3109.             s1 = s1 + Join(result2, " ")
  3110.             result = Split(s1, " ")
  3111.         Next
  3112.     End If
  3113.  
  3114.     ListaArquivos = result
  3115. ErrHandler:
  3116.     Set FSO = Nothing
  3117.     Set Pasta = Nothing
  3118.     Set arquivo = Nothing
  3119. End Function
  3120.  
  3121.  
  3122.  
  3123.  
  3124. Public Function canalizados_pla(Filename As Variant) As String
  3125.  
  3126. ' Declaracao de variaveis
  3127.  
  3128.  
  3129.   Dim sheet  As Worksheet
  3130.   Dim celula, celula1 As Range
  3131.   Dim LastRow As Long
  3132.  
  3133.    Dim Filter As String
  3134.    Dim FilterIndex As Integer
  3135.    'Dim filename As Variant
  3136.   Dim remove As String
  3137.    Dim path As String
  3138.    Dim filename_path As Variant
  3139.    
  3140.    
  3141.    Dim canalizados() As canalizados
  3142.    Dim array_temp() As array_canal
  3143.    ReDim Preserve canalizados(0)
  3144.    ReDim Preserve array_temp(0)
  3145.    Dim ultima_milha() As ultima_milha
  3146.    ReDim Preserve ultima_milha(0)
  3147.    Dim mux As String
  3148.    
  3149.  'Não atualizar a tela durante o script.
  3150.  'Application.ScreenUpdating = False
  3151.  
  3152. ' File filters - Filtro dos tipos de arquivos que aparecem na caixa de dialogo de escolha do arquivo.
  3153. 'Filter = "Excel Files (*.xls),*.xls," & _
  3154.         '"Text Files (*.txt),*.txt," & _
  3155.         '"All Files (*.*),*.*"
  3156. '   Default filter to *.*
  3157.    'FilterIndex = 3
  3158. ' Set Dialog Caption
  3159. 'TITULO DA CAIXA
  3160. 'Title = "Escolha o arquivo de circuitos "
  3161. ' Select Start Drive & Path - Caminho da caixa de dialogo.
  3162. 'ChDrive ("C")
  3163. 'ChDir ("C:\")
  3164.  
  3165. 'ABRE CADA ARQUIVO SELECIONADO DA CAIXA DE DIALOGO
  3166. 'With Application
  3167.    'Set File Name Array to selected Files (allow multiple)
  3168.    'Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  3169.    'Reset Start Drive/Path
  3170.    'ChDrive (Left(.DefaultFilePath, 1))
  3171.    'ChDir (.DefaultFilePath)
  3172. 'End With
  3173. 'Exit on Cancel
  3174.  
  3175. ' File filters
  3176.  
  3177.  
  3178. 'principal = ActiveWorkbook.Name
  3179. 'Workbooks.Add
  3180. 'ActiveWorkbook.Activate
  3181. 'plan_erro = ActiveWorkbook.Name
  3182.  
  3183. ' Open Files
  3184.  
  3185. tamanho_filename = UBound(Filename)
  3186.  
  3187. If tamanho_filename = 0 Then
  3188.  
  3189.     inicio = 0
  3190.     fim = 0
  3191.  
  3192. Else
  3193.  
  3194.     inicio = LBound(Filename)
  3195.     fim = (UBound(Filename)) - 1
  3196.  
  3197.  
  3198. End If
  3199.  
  3200.  
  3201.  
  3202. For sasa = inicio To fim  ' FOR abre arquivos
  3203.    msg = msg & Filename(sasa) & vbCrLf    ' This can be removed
  3204.    'Workbooks.Open Filename(sasa), False
  3205.    
  3206.     formata = sicop(Filename(sasa))
  3207.    
  3208.     arquivo = ActiveWorkbook.Name
  3209.    
  3210.     If arquivo Like "*Interior*" Then
  3211.  
  3212.         caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
  3213.  
  3214.     Else
  3215.  
  3216.         caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
  3217.  
  3218.     End If
  3219.  
  3220.     end2 = (caminhoarquivo & "\" & arquivo)
  3221.    
  3222.    
  3223.     Windows(arquivo).Activate
  3224.    
  3225.     For Each sheet In ActiveWorkbook.Worksheets
  3226.      
  3227.         If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  3228.  
  3229.                 sheet.Select
  3230.                
  3231.                 aba = sheet.Name
  3232.                
  3233.                 If WorksheetFunction.CountA(Cells) > 0 Then
  3234.                     'Search for any entry, by searching backwards by Rows.
  3235.                    LastRow = Cells.Find(What:="*", After:=[A1], _
  3236.                                          SearchOrder:=xlByRows, _
  3237.                                          SearchDirection:=xlPrevious).Row
  3238.  
  3239.                 End If
  3240.                
  3241.                 For Each celula In Range("C3:C" & LastRow)
  3242.                
  3243.                     linha = celula.Row
  3244.                    
  3245. '                    If Trim(UCase(Range("C" & linha).Value)) = "BHEFDT2 BHETFA4 1984K-01" Then
  3246. '
  3247. '                        bla111 = 0
  3248. '
  3249. '                    End If
  3250.                    
  3251.                
  3252.                                        
  3253.                     If Range("C" & linha).Interior.ColorIndex = 1 Then
  3254.                    
  3255.                         mux_milha = Range("C" & linha).Value
  3256.                        
  3257.                         If Not IsEmpty(Range("K" & linha)) And RemoveSpaces(Range("K" & linha).Value) <> "" Then
  3258.                        
  3259.                             tipo_mux = Range("K" & linha).Value
  3260.                        
  3261.                         ElseIf Not IsEmpty(Range("L" & linha)) And RemoveSpaces(Range("L" & linha).Value) <> "" Then
  3262.                        
  3263.                             tipo_mux = Range("L" & linha).Value
  3264.                        
  3265.                         Else
  3266.                        
  3267.                             tipo_mux = Range("M" & linha).Value
  3268.                        
  3269.                         End If
  3270.                    
  3271.                     End If
  3272.                    
  3273.                    
  3274.                    
  3275.                         If Not IsEmpty(Range("L" & linha)) And RemoveSpaces(Range("L" & linha).Value) <> "" Then
  3276.                        
  3277.                             slot_mux = UCase(Range("L" & linha).Value)
  3278.                            
  3279.                             If InStr(1, slot_mux, "S") <> 0 Then
  3280.                            
  3281.                                 slot_mux = Replace(slot_mux, "S", "")
  3282.                            
  3283.                             End If 'If InStr(1, slot_mux, "S") <> 0 Then
  3284.                        
  3285.                         End If 'If Not IsEmpty(Range("L" & linha)) And RemoveSpaces(Range("L" & linha).Value) <> "" Then
  3286.                        
  3287.                     If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
  3288.                        
  3289.                         If Not IsEmpty(Range("M" & linha)) And RemoveSpaces(Range("M" & linha).Value) <> "" Then
  3290.                        
  3291.                             porta_mux = UCase(Range("M" & linha).Value)
  3292.                            
  3293.                             If InStr(1, porta_mux, "P") <> 0 Then
  3294.                            
  3295.                                 porta_mux = Replace(porta_mux, "P", "")
  3296.                            
  3297.                             End If
  3298.                            
  3299.                             If InStr(1, porta_mux, ".") <> 0 Then
  3300.                            
  3301.                                 porta_mux = Replace(porta_mux, ".", ",")
  3302.                            
  3303.                             End If
  3304.                            
  3305.                             search_letra = letra_func(porta_mux)
  3306.                            
  3307.                             If search_letra <> 0 Then
  3308.                            
  3309.                                 porta_mux = search_letra
  3310.                            
  3311.                            
  3312.                             End If
  3313.                            
  3314.                            
  3315.                        
  3316.                         End If
  3317.                        
  3318.                         velocidade = Range("D" & linha).Value
  3319.                        
  3320.                         canal = checa_canalizado(velocidade)
  3321.                        
  3322.                         If canal = 1 Then
  3323.                        
  3324.                             If InStr(1, Range("C" & linha).Value, "  ") <> 0 Then
  3325.                            
  3326.                                 Range("C" & linha).Value = Replace(Range("C" & linha).Value, "  ", " ")
  3327.                                
  3328.                             ElseIf InStr(1, Range("C" & linha).Value, "   ") <> 0 Then
  3329.                            
  3330.                                 Range("C" & linha).Value = Replace(Range("C" & linha).Value, "   ", " ")
  3331.                            
  3332.                             End If
  3333.                        
  3334.                             ultima_milha(UBound(ultima_milha)).circuito = UCase(Trim(Range("C" & linha).Value))
  3335.                             ultima_milha(UBound(ultima_milha)).mux = mux_milha
  3336.                             ultima_milha(UBound(ultima_milha)).arquivo = arquivo
  3337.                             ultima_milha(UBound(ultima_milha)).aba = aba
  3338.                             ultima_milha(UBound(ultima_milha)).subend = ("'" & aba & "'!" & RemoveDolars(Range("C" & linha).Address))
  3339.                             ultima_milha(UBound(ultima_milha)).end2 = end2
  3340.                             ultima_milha(UBound(ultima_milha)).porta_mux = porta_mux
  3341.                             ultima_milha(UBound(ultima_milha)).slot_mux = slot_mux
  3342.                             ultima_milha(UBound(ultima_milha)).tipo_mux = tipo_mux
  3343.                                                        
  3344.                             ReDim Preserve ultima_milha(UBound(ultima_milha) + 1)
  3345.                        
  3346.                        
  3347.                         End If ' If canal = 1 Then
  3348.                    
  3349.                    
  3350.                     End If 'If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
  3351.                
  3352.                
  3353.                 Next
  3354.                
  3355.                
  3356.                
  3357.      
  3358.         End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  3359.    Next 'For Each sheet In ActiveWorkbook.Worksheets
  3360.    
  3361.    
  3362.     Windows(arquivo).Close False
  3363. Next
  3364.  
  3365. profile_folder = GetSpecialFolderPaths()
  3366. array_canalizados = profile_folder & "\SICOP\Facilidades\Canalizados\"
  3367.  
  3368.  'SALVA O NOME DA PLANILHA (ARQUIVO) ABERTA PARA TRANSIÇÃO ENTRE PLANILHA
  3369. principal = ActiveWorkbook.Name
  3370.  
  3371. 'ABRE UMA NOVA PLANILHA
  3372. 'Workbooks.Add
  3373. 'ActiveWorkbook.Activate
  3374. 'SALVA O NOME DA NOVA PLANILHA
  3375. 'erros = ActiveWorkbook.Name
  3376. 'Windows(erros).Activate
  3377.  
  3378. 'ABRE UMA NOVA PLANILHA
  3379. Workbooks.Add
  3380. ActiveWorkbook.Activate
  3381. 'SALVA O NOME DA NOVA PLANILHA
  3382. nova = ActiveWorkbook.Name
  3383. 'Windows(nova).Activate
  3384.  
  3385.  'For ca = LBound(array_canalizados) To UBound(array_canalizados) ' FOR abre pastas
  3386.  
  3387. 'Pega o caminho de todos os arquivos dentro de uma pasta
  3388. path = array_canalizados
  3389.  
  3390.  
  3391. 'path = "C:\Users\ljunqueira\Documents\Sicop\teste"
  3392. filename_path = ListaArquivos(path)
  3393.  
  3394. If Not IsArray(filename_path) Then
  3395.     MsgBox "Nenhum arquivo selecionado."
  3396.     Exit Function
  3397. End If
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403. ' Open Files - ABRE CADA UM DOS ARQUIVOS SELECIONADOS NA CAIXA DE DIALOGO EM UM LOOP
  3404. For sasa = LBound(filename_path) To UBound(filename_path) ' FOR abre arquivos
  3405.    If InStr(1, UCase(filename_path(sasa)), "XLS") <> 0 Then
  3406.    
  3407.         msg = msg & filename_path(sasa) & vbCrLf ' This can be removed
  3408.        
  3409.         If InStr(1, filename_path(sasa), "?") <> 0 Then
  3410.        
  3411.             filename_path(sasa) = Replace(filename_path(sasa), "?", " ")
  3412.        
  3413.         End If
  3414.        
  3415.         Workbooks.Open filename_path(sasa), False
  3416.        
  3417.         'SALVA O NOME DA PLANILHA ABERTA QUE FOI SELECIONADA NA CAIXA DE DIALOGO
  3418.        arquivo = ActiveWorkbook.Name
  3419.         'ATIVA A PLANILHA INICIAL ONDE O SCRIPT ESTA RODANDO
  3420.        Windows(arquivo).Activate
  3421.         'DEFINE O CAMINHO DA PLANILHA ATUAL
  3422.        caminhoarquivo = ActiveWorkbook.path
  3423.         'CRIA O CAMINHHO + NOME DA PLANILHA ATUAL
  3424.        end2 = (caminhoarquivo & "\" & arquivo)
  3425.    
  3426.        
  3427.         'EXECUTA UM LOOP EM CADA UMA DAS ABAS DA PLANILHA ABERTA
  3428.        
  3429.         For Each sheet In ActiveWorkbook.Worksheets
  3430.  
  3431.         canalizado = ""
  3432.         circuito = ""
  3433.  
  3434.             If UCase(sheet.Name) <> "ÍNDICE" Then
  3435.            
  3436.                 sheet.Select
  3437.        
  3438.                 aba = sheet.Name
  3439.            
  3440.                 If ((Trim(UCase(Range("A1").Value)) Like "*FACILIDADE*") And (Trim(UCase(Range("D1").Value)) = "CIRCUITOS")) Then
  3441.  
  3442.                     If WorksheetFunction.CountA(Cells) > 0 Then
  3443.                         'Search for any entry, by searching backwards by Rows.
  3444.                        LastRow = Cells.Find(What:="*", After:=[A1], _
  3445.                                              SearchOrder:=xlByRows, _
  3446.                                              SearchDirection:=xlPrevious).Row
  3447.        
  3448.                     End If
  3449.        
  3450.                     For Each celula In Range("A1:A" & LastRow)
  3451.        
  3452.                         linha = celula.Row
  3453.                         Range("D" & linha).Select
  3454.                        
  3455.                         If canalizado <> "" And Not IsEmpty(Range("D" & linha).Value) And Range("D" & linha).Interior.ColorIndex <> 1 And linha <> 1 And circuito = "" And InStr(UCase(Range("D" & linha).Value), "EXCLUSIVO") = 0 Then
  3456.        
  3457.                             circuito = Trim(Range("D" & linha).Value)
  3458.                            
  3459.                             If InStr(1, circuito, "  ") <> 0 Then
  3460.                            
  3461.                                 circuito = Replace(circuito, "  ", " ")
  3462.                                
  3463.                             ElseIf InStr(1, circuito, "   ") <> 0 Then
  3464.                            
  3465.                                 circuito = Replace(circuito, "   ", " ")
  3466.                            
  3467.                             End If
  3468.                            
  3469.                             ts_ini = Range("B" & linha).Value
  3470.                            
  3471.                             If Len(ts_ini) = 1 Then
  3472.                            
  3473.                                 ts_ini = "0" & ts_ini
  3474.                            
  3475.                             End If
  3476.        
  3477.                         End If
  3478.                        
  3479.                         If linha <> 1 Then
  3480.                        
  3481.                             canalizado = Trim(Range("A" & linha).Value)
  3482.                            
  3483.                             If InStr(1, canalizado, "  ") <> 0 Then
  3484.                            
  3485.                                 canalizado = Replace(canalizado, "  ", " ")
  3486.                                
  3487.                             ElseIf InStr(1, canalizado, "   ") <> 0 Then
  3488.                            
  3489.                                 canalizado = Replace(canalizado, "   ", " ")
  3490.                            
  3491.                             End If
  3492.                            
  3493.                             If InStr(1, canalizado, "/") <> 0 Then
  3494.                            
  3495.                                 canalizado = Replace(canalizado, "/", "")
  3496.                            
  3497.                             End If
  3498.                        
  3499.                             circuito_atual = Range("D" & linha).Value
  3500.                             x = Range("C" & linha).Value
  3501.                             ts = Range("B" & linha).Value
  3502.                             cor_linha = Range("D" & linha).Interior.ColorIndex
  3503.                            
  3504.                             If circuito_atual <> circuito And ts <> ts_ini And cor_linha <> 1 And Not IsEmpty(circuito_atual) Then
  3505.                            
  3506.                                         ts_fim = Range("B" & (linha - 1)).Value
  3507.                                        
  3508.                                         If Len(ts_fim) = 1 Then
  3509.                                        
  3510.                                             ts_fim = "0" & ts_fim
  3511.                                        
  3512.                                         End If
  3513.                                
  3514.                                         canalizados(UBound(canalizados)).facilidade = canalizado
  3515.                                         canalizados(UBound(canalizados)).circuito = RemoveSpaces(UCase(circuito))
  3516.                                         canalizados(UBound(canalizados)).vc = "'" & ts_ini & "-" & ts_fim
  3517.                                         canalizados(UBound(canalizados)).aba = aba
  3518.                                         canalizados(UBound(canalizados)).arquivo = arquivo
  3519.                                         'canalizados(UBound(canalizados)).subend = ("'" & aba & "'!" & Removedolars(Range("D" & linha).Address))
  3520.                                        
  3521.                                         ReDim Preserve canalizados(UBound(canalizados) + 1)
  3522.                                        
  3523.                                         ts_ini = Range("B" & linha).Value
  3524.                                        
  3525.                                         If Len(ts_ini) = 1 Then
  3526.                                
  3527.                                             ts_ini = "0" & ts
  3528.                            
  3529.                                         End If
  3530.                                        
  3531.                                         circuito = Range("D" & linha).Value
  3532.                            
  3533.                            
  3534.                             End If
  3535.                            
  3536.                             If (RemoveSpaces(UCase(Range("C" & linha - 1).Value)) = "X" And IsEmpty(x)) Or (UCase(RemoveSpaces(x)) Like "*EXCLUSIVO*") Then
  3537.                            
  3538.                                         ts_fim = Range("B" & (linha - 1)).Value
  3539.                                        
  3540.                                         If Len(ts_fim) = 1 Then
  3541.                                
  3542.                                             ts_fim = "0" & ts
  3543.                            
  3544.                                         End If
  3545.                                        
  3546.                                         If canalizado = "" Then
  3547.                                        
  3548.                                             canalizado = Range("A" & (linha - 1)).Value
  3549.                                            
  3550.                                             If InStr(1, canalizado, "/") <> 0 Then
  3551.                                            
  3552.                                                 canalizado = Replace(canalizado, "/", "")
  3553.                                            
  3554.                                             End If
  3555.                                                            
  3556.                                             If InStr(1, canalizado, "  ") <> 0 Then
  3557.                                            
  3558.                                                 canalizado = Replace(canalizado, "  ", " ")
  3559.                                                
  3560.                                             ElseIf InStr(1, canalizado, "   ") <> 0 Then
  3561.                                            
  3562.                                                 canalizado = Replace(canalizado, "   ", " ")
  3563.                                            
  3564.                                             End If
  3565.  
  3566.                                        
  3567.                                         End If
  3568.                                        
  3569.                                         canalizados(UBound(canalizados)).facilidade = Trim(canalizado)
  3570.                                         canalizados(UBound(canalizados)).circuito = RemoveSpaces(UCase(circuito))
  3571.                                         canalizados(UBound(canalizados)).vc = "'" & ts_ini & "-" & ts_fim
  3572.                                         canalizados(UBound(canalizados)).aba = aba
  3573.                                         canalizados(UBound(canalizados)).arquivo = arquivo
  3574.                                         'canalizados(UBound(canalizados)).subend = ("'" & aba & "'!" & Removedolars(Range("D" & linha).Address))
  3575.                                        
  3576.                                         ReDim Preserve canalizados(UBound(canalizados) + 1)
  3577.                                        
  3578.                                         ts_ini = ""
  3579.                                         circuito = ""
  3580.                            
  3581.                             End If
  3582.                        
  3583.                         End If '    If linha <> 1 Then
  3584.        
  3585.                     Next
  3586.                    
  3587.                     If linha = LastRow And RemoveSpaces(UCase(Range("C" & linha).Value)) = "X" Then
  3588.                
  3589.                                     ts_fim = Range("B" & (linha)).Value
  3590.                                    
  3591.                                     If Len(ts_fim) = 1 Then
  3592.                                
  3593.                                             ts_fim = "0" & ts
  3594.                            
  3595.                                     End If
  3596.                            
  3597.                                     canalizados(UBound(canalizados)).facilidade = canalizado
  3598.                                     canalizados(UBound(canalizados)).circuito = UCase(RemoveSpaces(circuito))
  3599.                                     canalizados(UBound(canalizados)).vc = "'" & ts_ini & "-" & ts_fim
  3600.                                     canalizados(UBound(canalizados)).aba = aba
  3601.                                     canalizados(UBound(canalizados)).arquivo = arquivo
  3602.                                     'canalizados(UBound(canalizados)).subend = ("'" & aba & "'!" & Removedolars(Range("D" & linha).Address))
  3603.                                    
  3604.                                     ReDim Preserve canalizados(UBound(canalizados) + 1)
  3605.                                    
  3606.                                     ts_ini = ""
  3607.                                     circuito = ""
  3608.                
  3609.                     End If
  3610.                
  3611.                 Else
  3612.                         subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("A1").Address))
  3613.                         'retorno_erro = 'erro(erros, arquivo, end2, subend_erro, Range("A1").Value, "Erro - Arquivo não formatado  : " & end2 & "\" & arquivo)
  3614.  
  3615.                 End If ' If ((Trim(UCase(Range("A1").Value)) <> "FACILIDADES") Or (Trim(UCase(Range("D1").Value)) <> "CIRCUITOS")) Then
  3616.                
  3617.             End If 'If UCase(sheet.Name) <> "ÍNDICE" Then
  3618.  
  3619.         Next 'For Each sheet In ActiveWorkbook.Worksheets
  3620.  
  3621.         'FECHA O ARQUIVO ABERTO SELECIONADO NA CAIXA DE DIALOGO PARA CONTINUAR O LOOP
  3622.        Windows(arquivo).Close False
  3623.     End If ' If InStr(1, Filename(sasa), "xls") <> 0 Then
  3624. Next ' cada arquivo - FOR
  3625.  
  3626. linhas = 1
  3627.  
  3628. For y = LBound(ultima_milha) To (UBound(ultima_milha) - 1)
  3629.  
  3630.     circuito_original = ultima_milha(y).circuito
  3631.     valor = RemoveSpaces(UCase(circuito_original))
  3632.    
  3633.     t = 0
  3634.    
  3635.     Erase array_temp
  3636.     ReDim Preserve array_temp(0)
  3637.    
  3638.     For i = LBound(canalizados) To UBound(canalizados)
  3639.    
  3640.         If valor = canalizados(i).circuito Then
  3641.        
  3642.             array_temp(t).n64 = canalizados(i).circuito
  3643.             array_temp(t).ts = canalizados(i).vc
  3644.             array_temp(t).facilidade = canalizados(i).facilidade
  3645.                    
  3646.             ReDim Preserve array_temp(UBound(array_temp) + 1)
  3647.            
  3648.             t = t + 1
  3649.        
  3650.         End If
  3651.    
  3652.     Next
  3653.    
  3654.    Windows(nova).Activate
  3655.    
  3656.     Range("A" & linhas).Value = ultima_milha(y).mux
  3657.     'Range("B" & linhas).Value = circuito_original
  3658.    Range("B" & linhas).Select
  3659.     ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=ultima_milha(y).end2, SubAddress:=ultima_milha(y).subend, TextToDisplay:=ultima_milha(y).circuito
  3660.    
  3661.     ultima_coluna = 3
  3662.    
  3663.     For i = LBound(array_temp) To (UBound(array_temp) - 1)
  3664.    
  3665.         Range(ConvertToLetter(ultima_coluna) & linhas).Value = array_temp(i).facilidade
  3666.         Range(ConvertToLetter(ultima_coluna + 1) & linhas).Value = array_temp(i).ts
  3667.            
  3668.         ultima_coluna = ultima_coluna + 2
  3669.            
  3670.    
  3671.     Next
  3672.    
  3673.     linhas = linhas + 1
  3674.  
  3675. Next ' For y = LBound(ultima_minha) To (UBound(ultima_milha) - 1)
  3676.  
  3677. Dim swap() As String
  3678. ReDim Preserve swap(0)
  3679. swap_ok = 0
  3680.  
  3681. Windows(nova).Activate
  3682.  
  3683. If WorksheetFunction.CountA(Cells) > 0 Then
  3684.     'Search for any entry, by searching backwards by Rows.
  3685.    LastRow = Cells.Find(What:="*", After:=[A1], _
  3686.                          SearchOrder:=xlByRows, _
  3687.                          SearchDirection:=xlPrevious).Row
  3688.  
  3689. End If
  3690.  
  3691. For Each celula In Range("A1:A" & LastRow)
  3692.  
  3693.     linha = celula.Row
  3694.    
  3695.     mux = Range("A" & linha).Value
  3696.    
  3697.     canalizado = Range("B" & linha).Value
  3698.    
  3699.     ultima_coluna = LastColumnInOneRow(linha)
  3700.    
  3701.     For i = 2 To ultima_coluna
  3702.    
  3703.         If i Mod 2 = 1 Then
  3704.        
  3705.        
  3706.             facilidade = Range(ConvertToLetter(i) & linha).Value
  3707.            
  3708.             comeco = Mid(facilidade, 1, InStr(1, facilidade, " ") - 1)
  3709.    
  3710.             intermed = Mid(facilidade, InStr(1, facilidade, " ") + 1, Len(facilidade))
  3711.    
  3712.             fim = Mid(intermed, 1, InStr(1, intermed, " ") - 1)
  3713.            
  3714.             equip1 = Mid(comeco, 4, Len(comeco))
  3715.             equip2 = Mid(fim, 4, Len(fim))
  3716.            
  3717.             If InStr(1, equip1, mux) <> 0 Then
  3718.            
  3719.                 If coluna_inicio = "" Then
  3720.                
  3721.                     coluna_inicio = ConvertToLetter(i)
  3722.                     prox_equip = equip2
  3723.                
  3724.                 Else
  3725.                            
  3726.                     'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - O canalizado Nx64 tem mais de uma origem : " & canalizado)
  3727.                            
  3728.                 End If 'If coluna_inicio = "" Then
  3729.                
  3730.            
  3731.             ElseIf InStr(1, equip2, mux) <> 0 Then
  3732.            
  3733.                 If coluna_inicio = "" Then
  3734.                
  3735.                     coluna_inicio = ConvertToLetter(i)
  3736.                     prox_equip = equip1
  3737.                
  3738.                 Else
  3739.                            
  3740.                     'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - O canalizado Nx64 tem mais de uma origem : " & canalizado)
  3741.                            
  3742.                 End If 'If coluna_inicio = "" Then
  3743.            
  3744.            
  3745.            
  3746.             End If 'If InStr(1, equip1, mux) <> 0 Then
  3747.    
  3748.         End If ' If i Mod 2 = 1 Then
  3749.    
  3750.     Next 'For i = 2 To ultima_coluna
  3751.    
  3752.    
  3753.     If coluna_inicio <> "" Then
  3754.    
  3755.        
  3756.         swap(UBound(swap)) = coluna_inicio
  3757.         ReDim Preserve swap(UBound(swap) + 1)
  3758.        
  3759.         iteracoes = (ultima_coluna / 2) - 1
  3760.        
  3761.         For i = 1 To iteracoes
  3762.        
  3763.             procura = procura_next(prox_equip, coluna_inicio, linha, ultima_coluna)
  3764.            
  3765.             If procura <> 0 Then
  3766.            
  3767.                 nova_coluna = Mid(procura, 1, InStr(1, procura, ".") - 1)
  3768.                 novo_equip = Mid(procura, InStr(1, procura, ".") + 1, Len(procura))
  3769.                
  3770.                 swap(UBound(swap)) = nova_coluna
  3771.                 ReDim Preserve swap(UBound(swap) + 1)
  3772.                
  3773.                 prox_equip = novo_equip
  3774.                 coluna_inicio = nova_coluna
  3775.            
  3776.             Else ' If procura <> 0 Then
  3777.            
  3778.                 tam_array = UBound(swap)
  3779.                
  3780.                 facilidade = Range("B" & linha).Value
  3781.                    
  3782.                 num_espaco = countSeparators(facilidade, " ")
  3783.                    
  3784.                 If num_espaco = 2 Then
  3785.                
  3786.                     If iteracoes = tam_array Then
  3787.                  
  3788.                         comeco = Mid(facilidade, 1, InStr(1, facilidade, " ") - 1)
  3789.                
  3790.                         intermed = Mid(facilidade, InStr(1, facilidade, " ") + 1, Len(facilidade))
  3791.                
  3792.                         fim = Mid(intermed, 1, InStr(1, intermed, " ") - 1)
  3793.                        
  3794.                         equip1 = Mid(comeco, 4, Len(comeco))
  3795.                         equip2 = Mid(fim, 4, Len(fim))
  3796.                        
  3797.                         If InStr(1, equip1, prox_equip) <> 0 Then
  3798.                        
  3799.                             swap_ok = 1
  3800.                        
  3801.                         ElseIf InStr(1, equip2, prox_equip) <> 0 Then ' If InStr(1, equip1, prox_equip) <> 0 Then
  3802.                        
  3803.                             swap_ok = 1
  3804.                        
  3805.                         End If ' If InStr(1, equip1, prox_equip) <> 0 Then
  3806.                    
  3807.                     End If ' If iteracoes = tam_array Then
  3808.                
  3809.                 Else '  If num_espaco = 2 Then
  3810.                
  3811.                     'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - Designacao invalida para o circuito : " & facilidade)
  3812.                
  3813.                 End If
  3814.            
  3815.             End If ' If procura <> 0 Then
  3816.            
  3817.        
  3818.         Next 'For i = 1 To iteracoes
  3819.        
  3820.     End If
  3821.    
  3822.     If swap_ok = 0 Then
  3823.    
  3824.         'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - Não foram encontrados todos os 2M para o canalizado : " & canalizado)
  3825.    
  3826.    
  3827.     Else
  3828.    
  3829.         ordenado_function = ordena_swap(swap(), linha)
  3830.    
  3831.     End If
  3832.  
  3833.  
  3834.     coluna_inicio = ""
  3835.     swap_ok = 0
  3836.     ReDim swap(0)
  3837.  
  3838. Next 'For Each celula In Range("A1:A" & LastRow)
  3839.  
  3840. If WorksheetFunction.CountA(Cells) > 0 Then
  3841.     'Search for any entry, by searching backwards by Rows.
  3842.    LastRow = Cells.Find(What:="*", After:=[A1], _
  3843.                          SearchOrder:=xlByRows, _
  3844.                          SearchDirection:=xlPrevious).Row
  3845.  
  3846. End If
  3847.  
  3848. For i = 1 To LastRow
  3849.  
  3850. circuito = Range("B" & i).Value
  3851.  
  3852.     For j = 0 To UBound(ultima_milha)
  3853.    
  3854.         circ_UM = ultima_milha(j).circuito
  3855.        
  3856.         If UCase(RemoveSpaces(circuito)) = UCase(RemoveSpaces(circ_UM)) Then
  3857.        
  3858.             'Range("W" & i) = ultima_milha(j).circuito
  3859.            Range("W" & i) = ultima_milha(j).mux
  3860.             Range("X" & i) = ultima_milha(j).tipo_mux
  3861.             Range("Y" & i) = ultima_milha(j).slot_mux
  3862.            
  3863.             If InStr(1, ultima_milha(j).porta_mux, ",") <> 0 Then
  3864.            
  3865.                 fracao_porta = Mid(ultima_milha(j).porta_mux, InStr(1, ultima_milha(j).porta_mux, ",") + 1, Len(ultima_milha(j).porta_mux))
  3866.                
  3867.                 ultima_milha(j).porta_mux = Mid(ultima_milha(j).porta_mux, 1, InStr(1, ultima_milha(j).porta_mux, ",") - 1)
  3868.                
  3869.                 If InStr(1, fracao_porta, ",") <> 0 Then
  3870.                
  3871.                     fracao_porta = Mid(fracao_porta, InStr(1, fracao_porta, ",") + 1, Len(fracao_porta))
  3872.                
  3873.                 End If
  3874.                
  3875.             Else
  3876.            
  3877.                 fracao_porta = 1
  3878.            
  3879.             End If
  3880.            
  3881.             Range("Z" & i) = ultima_milha(j).porta_mux
  3882.             Range("AA" & i) = fracao_porta
  3883.             'Range("AA" & linha).Select
  3884.            'ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=ultima_milha(j).end2, SubAddress:=subend, TextToDisplay:=circuito_plan
  3885.          Exit For
  3886.            
  3887.        
  3888.         End If 'If UCase(RemoveSpaces(circuito)) = UCase(RemoveSpaces(circ_UM)) Then
  3889.    
  3890.    
  3891.    
  3892.     Next 'For j = 0 To UBound(ultima_milha)
  3893.  
  3894.  
  3895.  
  3896. Next 'For i = 1 To LastRow
  3897.  
  3898. Range("A:A").Select
  3899. Selection.Delete Shift:=xlToLeft
  3900.  
  3901. Rows("1:1").Select
  3902. Selection.Insert Shift:=xlDown
  3903.  
  3904. Range("A1").Value = "N64"
  3905. Range("B1").Value = "Canalizado"
  3906. Range("C1").Value = "Timeslot"
  3907. Range("D1").Value = "Canalizado"
  3908. Range("E1").Value = "Timeslot"
  3909. Range("F1").Value = "Canalizado"
  3910. Range("G1").Value = "Timeslot"
  3911. Range("H1").Value = "Canalizado"
  3912. Range("I1").Value = "Timeslot"
  3913. Range("J1").Value = "Canalizado"
  3914. Range("K1").Value = "Timeslot"
  3915. Range("L1").Value = "Canalizado"
  3916. Range("M1").Value = "Timeslot"
  3917. Range("N1").Value = "Canalizado"
  3918. Range("O1").Value = "Timeslot"
  3919. Range("P1").Value = "Canalizado"
  3920. Range("Q1").Value = "Timeslot"
  3921. Range("R1").Value = "Canalizado"
  3922. Range("S1").Value = "Timeslot"
  3923. Range("T1").Value = "Canalizado"
  3924. Range("U1").Value = "Timeslot"
  3925. Range("V1").Value = "MUX"
  3926. Range("W1").Value = "TIPO_EQUIP"
  3927. Range("X1").Value = "SLOT"
  3928. Range("Y1").Value = "PORTA"
  3929. Range("Z1").Value = "FRACAO"
  3930.  
  3931.  
  3932.  
  3933. 'Next 'For ca = LBound(array_canalizados) To UBound(array_canalizados) ' FOR abre pastas
  3934.  
  3935.  
  3936. 'Application.ScreenUpdating = True
  3937.  
  3938. canalizados_pla = nova
  3939.  
  3940. End Function
  3941.  
  3942. Public Function sicop(ByVal arquivo_input As String) As Integer
  3943. 'Public Sub sicop()
  3944.  
  3945.  
  3946. Dim ciclo() As String
  3947. Dim ciclo_pop() As String
  3948. Dim ciclo_placa() As String
  3949. Dim mux() As String
  3950.  
  3951. 'CRIA A CONEXAO COM O BANCO
  3952.    Set rs = New ADODB.Recordset
  3953.  
  3954.     ConnectDB
  3955.  
  3956.     rs.ActiveConnection = conexao
  3957.     rs.LockType = adLockOptimistic
  3958.     rs.CursorLocation = adUseClient
  3959.     rs.CursorType = adOpenDynamic
  3960.  
  3961. 'DECLARACAO DE VARIAVEIS
  3962.    Dim sheet As Worksheet
  3963.     Dim celula, celula1 As Range
  3964.     Dim LastRow As Long
  3965.  
  3966.     Dim Filter As String
  3967.     Dim FilterIndex As Integer
  3968.     Dim Filename As Variant
  3969.     Dim remove As String
  3970.     Dim i As Integer
  3971.     ReDim Preserve ciclo(0)
  3972.     ReDim Preserve ciclo_pop(0)
  3973.     ReDim Preserve mux(0)
  3974.     ReDim Preserve ciclo_placa(0)
  3975.  
  3976.     Dim modens() As modens
  3977.     Dim placas() As placas
  3978.     Dim portas() As portas
  3979.     Dim tipo_modem() As tipo_modem
  3980.     ReDim Preserve modens(0)
  3981.     ReDim Preserve tipo_modem(0)
  3982.     ReDim Preserve placas(0)
  3983.     ReDim Preserve portas(0)
  3984.  
  3985.     Dim m As Integer
  3986.     Dim n As Integer
  3987.  
  3988.     rodada = 0
  3989.  
  3990.  
  3991. 'NAO ATUALIZA A TELA
  3992.   ' Application.ScreenUpdating = False
  3993. '
  3994. '
  3995. '    ' File filters
  3996. '    Filter = "Excel Files (*.xls),*.xls," & _
  3997. '             "Text Files (*.txt),*.txt," & _
  3998. '             "All Files (*.*),*.*"
  3999. '    '   Default filter to *.*
  4000. '    FilterIndex = 3
  4001. '    ' Set Dialog Caption
  4002. '    Title = "Escolha o arquivo de circuitos "
  4003. '    ' Select Start Drive & Path
  4004. '    ChDrive ("C")
  4005. '    ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia\Facilidades\2012-11-06")
  4006. '    With Application
  4007. '        ' Set File Name Array to selected Files (allow multiple)
  4008. '        Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  4009. '        ' Reset Start Drive/Path
  4010. '        ChDrive (Left(.DefaultFilePath, 1))
  4011. '        ChDir (.DefaultFilePath)
  4012. '    End With
  4013. '    ' Exit on Cancel
  4014. '
  4015. '    If Not IsArray(Filename) Then
  4016. '        MsgBox "Nenhum arquivo selecionado."
  4017. '        Exit Function
  4018. '    End If
  4019. 'CRIA 1 NOVA PLANILHA
  4020. '    principal = ActiveWorkbook.Name
  4021. '    Workbooks.Add
  4022. '    ActiveWorkbook.Activate
  4023. '    nova = ActiveWorkbook.Name
  4024. '    Windows(nova).Activate
  4025. '    Cells.Select
  4026. '    Selection.NumberFormat = "@"
  4027. '    Range("A1").Select
  4028. '    Workbooks.Add
  4029. '    ActiveWorkbook.Activate
  4030. '    plan_erro = ActiveWorkbook.Name
  4031.   ' Windows(principal).Activate
  4032.  
  4033. 'LOOP DOS ARQUIVOS SELECIONADOS - CONTROLE DE FACILIDADES
  4034.    ' Open Files
  4035.        'For sasa = LBound(filename) To UBound(filename)    ' FOR abre arquivos
  4036.    '    msg = msg & Filename(sasa) & vbCrLf    ' This can be removed
  4037.        Workbooks.Open arquivo_input, False
  4038.  
  4039.         arquivo = ActiveWorkbook.Name
  4040.         Windows(arquivo).Activate
  4041.         'caminhoarquivo = ActiveWorkbook.Path
  4042. 'DEFINE O CAMINHO DO ARQUIVO PARA CRIAR HYPERLINKS
  4043.        
  4044.         If arquivo Like "*Interior*" Then
  4045.  
  4046.             caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
  4047.  
  4048.         Else
  4049.  
  4050.             caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
  4051.  
  4052.         End If
  4053.  
  4054.         end2 = (caminhoarquivo & "\" & arquivo)
  4055.  
  4056.         'TRATA CADA UMA DAS ABAS DAS PLANILHAS
  4057.        For Each sheet In ActiveWorkbook.Worksheets
  4058.  
  4059.             rpt = 0
  4060. 'IGNORA TODAS AS PLANILHAS QUE TEM RPT NO NOME - PLANILHAS DE RÁDIO
  4061. '            If sheet.Name Like "*RPT*" Then
  4062. '
  4063. '                rpt = 1
  4064. '
  4065. '            End If
  4066. 'IGNORA AS PLANILHAS QUE NÃO SÃO ULTIMA MILHA
  4067.            If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" And rpt = 0 Then
  4068. 'SELECIONA A ABA
  4069.                sheet.Select
  4070.  
  4071.                 aba = sheet.Name
  4072. 'TRATA AS PLANILHAS QUE NÃO SÃO VESPER
  4073.                If sheet.Name <> "Sites_Vesper" Then
  4074. 'ARMAZENA O NOME DA PLANILHA
  4075.                    aba1 = sheet.Name
  4076.                     'ENCONTRA A SIGLA DO POP NO BANCO DE DADOS MYSQL
  4077.                    sigla_pop = acha_sigla_pop(aba1)
  4078.  
  4079.                 End If    'If sheet.Name <> "Sites_Vesper" Then
  4080.  
  4081.                 If WorksheetFunction.CountA(Cells) > 0 Then
  4082.                     'Search for any entry, by searching backwards by Rows.
  4083.                    LastRow = Cells.Find(What:="*", After:=[A1], _
  4084.                                          SearchOrder:=xlByRows, _
  4085.                                          SearchDirection:=xlPrevious).Row
  4086.                 End If
  4087. 'RESETA AS VARIÁVEIS PARA CADA CICLO - UM CICLO NESSE CASO É O INTERVALO ENTRE AS LINHAS PRETAS, QUE REPRESENTAM UM ÚNICO EQUIPAMENTO
  4088. 'O CICLO COMEÇA DA LINHA 4 PORQUE A LINHA 3 É A PRIMEIRA PRETA
  4089.                inicio = 4
  4090.                 ReDim ciclo(0)
  4091.                 ReDim ciclo_pop(0)
  4092.                 ReDim mux(0)
  4093.                 ReDim ciclo_placa(0)
  4094.                 i = 0
  4095.                 'ADICIONA O NOME DO MULTIPLEXADOR AO ARRAY MUX
  4096.                mux(0) = Range("C3").Value
  4097.                
  4098.                 'AUMENTA O TAMANHO DO ARRAY MUX
  4099.                ReDim Preserve mux(UBound(mux) + 1)
  4100.  
  4101.                 For Each celula In Range("C4:C" & LastRow)
  4102.                     'DEFINE OS RANGES DE CADA EQUIPAMENTO (LINHA PRETA) NA PLANILHA
  4103.                    'ISSO SIGNIFICA CRIAR UMA ESTRUTURA DE LOOP PARA DA INTERVALO ENTRE LINHAS PRETAS NA PLANILHA
  4104. 'LINHA CORRENTE
  4105.                    linha = celula.Row
  4106. 'VERIFICA SE A LINHA É PRETA E CASO A PLANILHA SEJA A VESPER, UM NOVO POP É INICIADO
  4107.                    If celula.Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
  4108.                         aba1 = Range("G" & linha).Value
  4109.                         sigla_pop = acha_sigla_pop(aba1)
  4110.                     End If
  4111. 'ENCONTRA A LINHA PRETA E DEFINE O FINAL DO "CICLO" DE UM EQUIPAMENTO
  4112.                    If celula.Interior.ColorIndex = 1 Then
  4113.  
  4114.                         fim = linha - 1
  4115. 'ADICIONA O CICLO AO ARRAY CICLO PARA GERAR UMA CADEIA DE LOOPS PARA IDENTIFICAR AS PLACAS, MUXS E POPS (VESPER)
  4116.                        ciclo(i) = "E" & inicio & ":E" & fim
  4117.                         ciclo_pop(i) = "I" & inicio & ":I" & fim
  4118.                         ciclo_placa(i) = "K" & inicio & ":K" & fim
  4119.                         mux(i + 1) = RemoveSpaces(UCase(Range("C" & linha).Value))
  4120.  
  4121. 'AUMENTA O TAMANHO DOS ARRAYS SEM PERDER OS DADOS
  4122.                        ReDim Preserve ciclo(UBound(ciclo) + 1)
  4123.                         ReDim Preserve ciclo_pop(UBound(ciclo_pop) + 1)
  4124.                         ReDim Preserve mux(UBound(mux) + 1)
  4125.                         ReDim Preserve ciclo_placa(UBound(ciclo_placa) + 1)
  4126.  
  4127.                         i = i + 1
  4128. 'REINICIA A VARIAVEL 'INICIO' PARA DAR CONTINUIDADE AO LOOP
  4129.                        inicio = linha + 1
  4130.  
  4131.                     End If    'If celula.Interior.ColorIndex = 1 Then
  4132.  
  4133.                 Next    ' For Each celula In Range("C4:C" & LastRow)
  4134. 'APOS IDENTIFICAR TODOS OS CICLOS, FINALIZA COM A ULTIMA LINHA PREENCHIDA DO ARQUIVO
  4135.                fim = LastRow
  4136.  
  4137.                 ciclo(i) = "E" & inicio & ":E" & fim
  4138.                 ciclo_pop(i) = "I" & inicio & ":I" & fim
  4139.                 ciclo_placa(i) = "K" & inicio & ":K" & fim
  4140.  
  4141.  
  4142.  
  4143. 'ESSE CICLO PEGA AS INFORMACOES DE CADA PLACA (COLUNA K) PARA IDENTIFICA-LAS CORRETAMENTE
  4144.                For i = 0 To UBound(ciclo_placa)
  4145.                     'RENOMEIA AS PLACAS DE CADA RANGE
  4146.  
  4147.                     For Each celula In Range(ciclo_placa(i))
  4148.  
  4149.                         linha_h = celula.Row
  4150.  
  4151.  
  4152.                         If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  4153. 'PEGA O NOME DA PLACA
  4154.                            placa = celula.Value
  4155.                             placa = UCase(RemoveSpaces((placa)))
  4156. 'ATUALIZA O OBJETO 'PLACAS' COM O NOME DA PLACA E UM SEQUENCIAL PARA IDENTIFICAR QUANTAS PLACAS DO MESMO TIPO EXISTEM NAQUELE EQUIPAMENTO
  4157.                            For t = 0 To UBound(placas)
  4158.                                 'PEGA A SEQUENCIA DE CADA PLACA REPETIDA
  4159.                                If placa = placas(t).nome Then
  4160.                                     placas(t).seq = placas(t).seq + 1
  4161.                                     seq_placa = placas(t).seq
  4162.                                     GoTo encontrado_placa
  4163.                                 End If    ' If placa = placas(t).nome Then
  4164.                            Next    ' For t = 0 To UBound(placa)
  4165.  
  4166.                             'SO SERA EXECUTADO SE NAO ACHAR PLACA
  4167. 'CASO NÃO EXISTA NENHUMA OCORRENCIA DA PLACA NO OBJETO 'PLACAS', ADICIONA UM NOVO ITEM COM O NOME DA PLACA NOVA
  4168.                            placas(UBound(placas)).nome = placa
  4169.                             placas(UBound(placas)).seq = 1
  4170.                             seq_placa = 1
  4171.                             ReDim Preserve placas(UBound(placas) + 1)
  4172.                             'SO SERA EXECUTADO SE NAO ACHAR PLACA
  4173.  
  4174.  
  4175. encontrado_placa:
  4176. 'APOS A PLACA TER SIDO CRIADA OU IDENTIFICADA, CRIA UM NOME PARA A PLACA NOS MOLDES - TIPO_DA_PLACA.MUX_ONDE_SE_ENCONTRA.SEQUENCIAL
  4177.                            nome_placa_mod = placa & "." & mux(i) & "." & seq_placa
  4178.  
  4179.                             celula.Value = nome_placa_mod
  4180.                             'REINICIA O ARRAY DE PORTAS PARA IDENTICAR AS PORTAS DA PLACA ATUAL
  4181.                            ReDim portas(0)
  4182.  
  4183.                         End If    ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  4184. 'INICIA A VARIAVEL DAS PORTAS
  4185.                        porta = ""
  4186.  
  4187. 'VERIFICA SE A EXISTE UMA PORTA ASSOCIADA AQUELA PLACA E SE A CELULA NAO ESTA VAZIA
  4188.                        If Not IsEmpty(celula.Next.Next.Value) And RemoveSpaces((celula.Next.Next.Value)) <> "" Then
  4189. 'ASSOCIA A PORTA A VARIAVEL
  4190.                            porta = celula.Next.Next.Value
  4191.                             porta = UCase(RemoveSpaces((porta)))
  4192.  
  4193.                         End If
  4194.  
  4195.                         If porta <> "" Then
  4196.                             'PEGA AS PORTAS DA PLACA
  4197. 'ASSOCIA CADA PORTA DAQUELA PLACA AO OBJETO 'PORTAS'
  4198.                            For t = 0 To UBound(portas)
  4199.  
  4200.                                 If porta = portas(t).nome Then
  4201.                                     portas(t).seq = portas(t).seq + 1
  4202.                                     seq_porta = portas(t).seq
  4203.                                     GoTo achou_porta
  4204.                                 End If
  4205.                             Next
  4206. 'CASO A PORTA NAO EXISTA, CRIA UMA NOVA ENTRADA
  4207.                            'SO SERA EXECUTADO SE NAO ACHAR PORTA
  4208.  
  4209.                             portas(UBound(portas)).nome = porta
  4210.                             portas(UBound(portas)).seq = 1
  4211.                             seq_porta = 1
  4212.                             ReDim Preserve portas(UBound(portas) + 1)
  4213.  
  4214.                             'SO SERA EXECUTADO SE NAO ACHAR PORTA
  4215.  
  4216. achou_porta:
  4217. 'CRIA UM IDENTIFICADOR PARA A PORTA NO FORMATO PORTA.SEQUENCIAL
  4218. 'CASO NAO EXISTA A LETRA P NO CAMPO ADICIONA ESSA LETRA AO NOME DA PORTA E GRAVA NA CELULA DA PORTA
  4219.                            If InStr(1, porta, "P") = 0 Then
  4220.  
  4221.                                 celula.Next.Next.Value = "'" & porta & "." & seq_porta
  4222.  
  4223.                             Else
  4224.  
  4225.                                 celula.Next.Next.Value = porta & "." & seq_porta
  4226.  
  4227.                             End If
  4228. 'VARIAVEL PARA VERIFICACAO SE A PORTA ESTA COM A CELULA HACHURADA
  4229.                            porta_hachurada = celula.Next.Next.Value
  4230.  
  4231.                             hachu_seq = 1
  4232.  
  4233.  
  4234.  
  4235.                         End If    'If porta <> "" Then
  4236. 'IF PARA VERIFICAR SE A PORTA ESTA HACHURADA. CASO ESTEJA, E A CELULA ESTEJA VAZIA, PREENCHE O DADO COM A ULTIMA PORTA ENCONTRADA
  4237.  
  4238.                         If IsEmpty(Range("M" & linha_h)) And RemoveSpaces(Range("M" & linha_h).Value) = "" And (Range("M" & linha_h).Interior.Pattern = 14 Or Range("M" & linha_h).Interior.Pattern = -4162) And Not IsEmpty(Range("C" & linha_h)) And RemoveSpaces(Range("C" & linha_h).Value) <> "" Then
  4239.  
  4240.                             Range("M" & linha_h).Value = porta_hachurada & "." & hachu_seq
  4241.                             hachu_seq = hachu_seq + 1
  4242.  
  4243.  
  4244.                         End If
  4245.  
  4246.  
  4247.                     Next    ' For Each celula In Range(ciclo_placa(i))
  4248. 'REINICIA O ARRAY DE PLACAS
  4249.                    ReDim placas(0)
  4250.  
  4251.                 Next    ' For i = 0 To UBound(ciclo_placa)
  4252.  
  4253.  
  4254. 'LOOP PARA IDENTIFICAR OS MODENS DO LADO DO POP - COLUNA E
  4255.                For i = 0 To UBound(ciclo)    'COLUNA E
  4256.  
  4257.                     For Each celula In Range(ciclo(i))
  4258.  
  4259.                         linha = celula.Row
  4260.                        
  4261.  
  4262. 'VERIFICA SE A CELULA ESA VAZIA, SE ESTIVER, 'RESETA' OS DADOS DA CELULA. ISSO PRECISA SER FEITO PORQUE MUITAS VEZES A FORMATACAO CONDICIONAL
  4263. 'SOBREPOE OS DADOS REAIS DA CELULA. EX. UMA CELULA ESTÁ COM FUNDO PRETO, MAS DECIDO A FORMATACAO CONDICIONAL ESSE ITEM APARECE BRANCO/VERDE/AMARELO/LARANJA
  4264.                        If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
  4265.  
  4266.                             Range("E" & linha).Select
  4267.                             Selection.Clear
  4268. '                           Range("E" & linha).Font.Bold = False
  4269.  
  4270.                         End If
  4271. 'FAZ A MESMA VERIFICACAO ACIMA, MAS PARA A PORTA
  4272.                        If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
  4273.  
  4274.                             Range("F" & linha).Select
  4275.                             Selection.Clear
  4276. '                          Range("F" & linha).Font.Bold = False
  4277.  
  4278.                         End If
  4279.  
  4280.                     Next 'For Each celula In Range(ciclo(i))
  4281.  
  4282.  
  4283.                     For Each celula In Range(ciclo(i))
  4284.  
  4285.                         linha = celula.Row
  4286. 'VERIFICAR SE AMBAS AS CELULAS DA COLUNA 'E' E 'F' NAO ESTAO VAZIAS
  4287.  
  4288.                         If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" And Range("F" & linha).Font.Color <> Range("E" & linha).Font.Color Then
  4289.  
  4290. 'VERIFICA SE A COR DA FONTE DO EQUIPAMENTO É DIFERENTE DA COR DA PORTA DAQUELE EQUIPAMENTO
  4291.                            If Range("E" & linha).Font.Color <> 0 And Range("F" & linha).Font.Color = 0 Then
  4292. 'EM CASO POSITIVO, COPIA A COR DA FONTE DO EQUIPAMENTO PARA SUA RESPECTIVA PORTA
  4293.                                Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  4294. 'FAZ A VERIFICACAO CONTRARIA - COR DA PORTA = COR DO EQUIPAMENTO
  4295.                            ElseIf Range("F" & linha).Font.Color <> 0 And Range("E" & linha).Font.Color = 0 Then
  4296.  
  4297.                                 Range("E" & linha).Font.Color = Range("F" & linha).Font.Color
  4298.  
  4299.                             End If
  4300.  
  4301.                         End If
  4302.  
  4303. 'VERIFICA SE HÁ UM CIRCUITO ASSOCIADO AQUELE EQUIPAMENTO E SE O EQUIPAMENTO E A PORTA EXISTEM
  4304.                        If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces((Range("C" & linha).Value)) <> "" And IsEmpty(Range("E" & linha).Value) And RemoveSpaces((Range("E" & linha).Value)) = "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces((Range("F" & linha).Value)) = "" Then
  4305. 'CASO NAO EXISTA EQUIPAMENTO, É CRIADO O EQUIPAMENTO 'CABO' COM SUA RESPECTIVA PORTA 'PO1'
  4306.  
  4307.                             Range("E" & linha).Value = "CABO"
  4308.                             Range("E" & linha).Font.Color = 0
  4309.                             Range("F" & linha).Value = "PO1"
  4310.                             Range("F" & linha).Font.Color = 0
  4311.  
  4312.  
  4313.                         End If
  4314.                        
  4315.                        
  4316.  
  4317. 'VERIFICA SE EXISTE UM EQUIPAMENTO MAS NAO EXISTE UMA PORTA ASSOCIADA A ELE
  4318.                        If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
  4319. 'CASO O EQUIPAMENTO SEJA UM ASGA, ADICIONA A PORTA P1 PARA ELE
  4320.                            If InStr(1, Range("E" & linha).Value, "ASGA") <> 0 Then
  4321.                            
  4322.                                 Range("F" & linha).Value = "P1"
  4323.                                
  4324.                             Else
  4325.                             'SE NAO FOR UM EQUIPAMENTO ASGA, CRIA A PORTA ESPECIAL 1 - PE1
  4326.                                Range("F" & linha).Value = "PE1"
  4327.                            
  4328.                             End If
  4329.                             'COLOCA A COR DA PORTA IGUAL A DO EQUIPAMENTO
  4330.                            
  4331.                             Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  4332.  
  4333.                         End If
  4334.  
  4335. 'NAO SEI PRA QUE ESSE CODIGO ABAIXO FOI COMENTADO.
  4336. '                        If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
  4337. '
  4338. '                            Range("F" & linha).Value = "PE1"
  4339. '                            Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  4340. '
  4341. '                        End If
  4342.  
  4343. 'VERIFICA SE EXISTE O EQUIPAMENTO, SE A PORTA E A PORTA ESTÁ VAZIA E SE O EQUIPAMENTO É UM DM706
  4344.                        If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" And UCase(Range("E" & linha).Value) = "DM706" Then
  4345. 'CASO SEJA, ADICIONA A PORTA P1 E REPETE A COR PARA O EQUIPAMENTO E PORTA
  4346.                            Range("F" & linha).Value = "P1"
  4347.                             Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
  4348.  
  4349.                         End If
  4350.  
  4351. 'CASO SEJA IDENTIFICADO O ITEM 'CPU64' NA COLUNA I, REMOVE ELE - NAO SERVE PARA NADA
  4352.  
  4353.                         If RemoveSpaces(UCase(Range("I" & linha).Value)) = "CPU64" Then
  4354.  
  4355.                             Range("I" & linha).Select
  4356.                             Selection.Clear
  4357.  
  4358.                         End If
  4359.  
  4360.                         'VERIFICA SE A CELULA DO EQUIPAMENTO NAO ESTA VAZIA
  4361.                        If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  4362. 'ASSOCIA O EQUIPAMENTO A VARIAVEL MODEM
  4363.                            modem = UCase(RemoveSpaces(celula.Value))
  4364.                             'CASO O EQUIPAMENTO SEJA UM CABO, MUDA O NOME PARA CABO_CLI
  4365.                            If modem = "CABO" Then
  4366.                                 modem = "CABO_CLI"
  4367.                             End If
  4368. 'ASSOCIA O NOME DO MODEM AO OBJETO-ARRAY MODENS
  4369.                            modens(UBound(modens)).nome = modem
  4370.  
  4371.                             'SE O EQUIPAMENTO NAO FOR UM CABO, ADICIONA A COR DA FONTE AO OBJETO-ARRAY
  4372.                            If modem <> "CABO" Then
  4373.  
  4374.                                 modens(UBound(modens)).cor_fonte = celula.Font.Color
  4375. 'EM CASO CONTRARIO, SETA A COR COMO 'AUTOMATICO'
  4376.                            Else
  4377.  
  4378.                                 modens(UBound(modens)).cor_fonte = 0
  4379.  
  4380.                             End If
  4381. 'ADICIONA A LINHA DE ONDE AQUELE MODEM VEIO
  4382.                            modens(UBound(modens)).linha = celula.Row
  4383.  
  4384. 'VERIFICA SE JÁ EXISTE O TIPO DE MODEM NA BASE, EM CASO NEGATIVO, CRIA O MODEM. EM CASO POSITIVO ADICIONA UM SEQUENCIAL PARA DIFERENCIACAO
  4385.                            For t = 0 To UBound(tipo_modem)
  4386.  
  4387.                                 If tipo_modem(t).nome = modem Then
  4388.                                     GoTo encontrado_tipo_modem
  4389.                                 End If
  4390.  
  4391.                             Next    'For t = 0 To UBound(tipo_modem)
  4392.  
  4393.                             'SO SERA EXECUTADO SE NAO ACHAR
  4394.  
  4395.                             tipo_modem(UBound(tipo_modem)).nome = modem
  4396.                             tipo_modem(UBound(tipo_modem)).seq = 1
  4397.                             ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
  4398.  
  4399.                             'SO SERA EXECUTADO SE NAO ACHAR
  4400.  
  4401. encontrado_tipo_modem:
  4402.  
  4403. 'AUMENTA O TAMANHO DO ARRAY
  4404.                            ReDim Preserve modens(UBound(modens) + 1)
  4405.  
  4406.  
  4407.  
  4408.                         End If  ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  4409.  
  4410.  
  4411.  
  4412.                     Next    'For Each celula In Range(ciclo(i))
  4413.  
  4414. 'FORMATA O TIPO DO MODEM E SUA COR PARA SER INSERIDO NA CELULA
  4415.                    For K = 0 To (UBound(modens) - 1)
  4416.  
  4417.                         nome_modem = modens(K).nome
  4418.                         cor_fonte_modem = modens(K).cor_fonte
  4419.  
  4420.                         For u = 0 To (UBound(tipo_modem) - 1)
  4421.  
  4422.                             If tipo_modem(u).nome = nome_modem Then
  4423.                                 seq_modem = tipo_modem(u).seq
  4424.                                 posicao_seq_modem = u
  4425.                                 Exit For
  4426.                             End If    'If tipo_modem(u).nome = nome_modem Then
  4427.  
  4428.                         Next    'For u = 0 To (UBound(tipo_modem) - 1)
  4429.  
  4430. 'IDENTIFICA A SIGLA DO CLIENTE A PARTIR DA DESIGNACAO PARA COMPOR O NOME DO MODEM
  4431.                        circuito_cliente = Range("C" & modens(K).linha).Value
  4432.  
  4433.                         sigla_cliente = ""
  4434.  
  4435. '                       sigla_cliente = detecta(circuito_cliente, arquivo, mux(i))
  4436.  
  4437.                         If sigla_cliente = "" Then
  4438.  
  4439.                             sigla_cliente = mux(i)
  4440.  
  4441.                         End If
  4442.  
  4443. 'GERA O NOME DO MODEM PARA ALTERAR A CELULA
  4444.                        nome_modem_mod = nome_modem & "." & sigla_cliente & "." & seq_modem
  4445. 'CASO A COR SEJA AUTOMATICA (0) O MODEM SERÁ INSERIDO COM O SEQUENCIAL '1'. SENDO ASSIM PULA A ETAPA DE IDENTIFICAR A COR E SEQUENCIAL DO MODEM (LOGO ABAIX0)
  4446.                        If cor_fonte_modem = 0 Then
  4447.  
  4448.                             modens(K).novo_nome = nome_modem_mod
  4449.                             tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  4450.                             GoTo linha_zero
  4451.  
  4452.                         End If    'If cor_fonte_modem = 0 Then
  4453.  
  4454. 'IDENTIFICA SE JÁ EXISTE O MODEM PELA COR DA FONTE, CASO EXISTA, PEGA O NOME DELE
  4455.                        For y = 0 To (UBound(modens) - 1)
  4456.  
  4457.                             If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  4458.  
  4459.                                 modens(y).novo_nome = nome_modem_mod
  4460.  
  4461.                             End If    'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  4462.  
  4463.  
  4464.                         Next    'For y = 0 To (UBound(modens) - 1)
  4465. 'ATUALIZA O SEQUENCIAL DO TIPO DO MODEM
  4466.                        tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  4467. linha_zero:
  4468. 'ATUALIZA O VALOR DA LINHA DO MODEM
  4469.                        Range("E" & modens(K).linha).Value = nome_modem_mod
  4470. 'CASO O MODEM SEJA CABO_CLI, CRIA A PORTA OTICA 1 - 'PO1'
  4471.                        If tipo_modem(posicao_seq_modem).nome = "CABO_CLI" Then
  4472.  
  4473.                             Range("E" & modens(K).linha).Next.Value = "PO1"
  4474.  
  4475.                         End If    'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
  4476.  
  4477.                     Next    ' For k = 0 To UBound(modens)
  4478.  
  4479.                     For Each celula In Range(ciclo(i))
  4480. 'LOOP PARA IDENTIFICAR QUAIS MODENS TEM COR DIFERENTE DA AUTOMATICA E SUAS PORTAS ASSOCIADAS
  4481.                        'COLOCA AS CORES DAS PORTAS NOS MODENS!!! (LADO CLIENTE)
  4482. 'VERIFICA SE A COR É DIFERENTE DE 0
  4483.                        If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
  4484.  
  4485.                             porta_cliente = celula.Next.Value
  4486.                             cor_porta_cliente = celula.Next.Font.Color
  4487.                             cor_encontrada = 0
  4488. 'PROCURA PELA COR NO ARRAY MODENS
  4489.                            For K = 0 To (UBound(modens) - 1)
  4490. 'CASO ENCONTRE, ASSOCIA O EQUIPAMENTO DA MESMA COR À PORTA ASSOCIADA A ELE
  4491.                                If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  4492.  
  4493.                                     celula.Value = modens(K).novo_nome
  4494.  
  4495.                                     '                                    celula.Font.Color = modens(k).cor_fonte
  4496.  
  4497.                                 End If    'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  4498.  
  4499.  
  4500.  
  4501.                             Next    'For k = 0 To (UBound(modens) - 1)
  4502.  
  4503. 'IF DE VERIFICACAO DEBUG
  4504. '                        If IsEmpty(celula) And RemoveSpaces(celula.Value) = "" Then
  4505. '
  4506. '                            laleq1a = 0
  4507. '
  4508. '                        End If
  4509.  
  4510.  
  4511.  
  4512.                         End If    'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
  4513.  
  4514.  
  4515.  
  4516.                     Next    'Each celula In Range(ciclo(i))
  4517. 'REINICIA OS MODENS E TIPOS DE MODENS PARA O PROXIMO MULTIPLEXADOR
  4518.                    ReDim modens(0)
  4519.                     ReDim tipo_modem(0)
  4520.  
  4521.                 Next    'For i = 0 To UBound(ciclo)
  4522.  
  4523.                 For i = 0 To UBound(ciclo_pop)    'CICLO MODENS LADO POP COLUNA I
  4524. 'LOOP QUE FAZ AS MESMAS COISAS DO LOOP ANTERIOR, SÓ QUE DESSA VEZ DO LADO DO CLIENTE, COLUNA I
  4525.                    For Each celula In Range(ciclo(i))
  4526.  
  4527.                         linha = celula.Row
  4528.                        
  4529.  
  4530.                         If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
  4531.  
  4532.                             Range("I" & linha).Font.Color = 0
  4533.                             Range("I" & linha).Font.Bold = False
  4534.  
  4535.                         End If
  4536.  
  4537.                         If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
  4538.  
  4539.                             Range("J" & linha).Font.Color = 0
  4540.                             Range("J" & linha).Font.Bold = False
  4541.  
  4542.                         End If
  4543.  
  4544.                     Next
  4545.  
  4546.                     For Each celula In Range(ciclo_pop(i))
  4547.  
  4548.                         linha = celula.Row
  4549.                        
  4550.  
  4551.                         If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  4552.  
  4553.                             modem = UCase(RemoveSpaces(celula.Value))
  4554.                             modens(UBound(modens)).nome = modem
  4555.                             modens(UBound(modens)).cor_fonte = celula.Font.Color
  4556.                             modens(UBound(modens)).linha = celula.Row
  4557.  
  4558.                             If modem <> "CPU64" Then
  4559.                                 For t = 0 To UBound(tipo_modem)
  4560.  
  4561.                                     If tipo_modem(t).nome = modem Then
  4562.                                         GoTo encontrado_tipo_modem_pop
  4563.                                     End If
  4564.  
  4565.                                 Next    'For t = 0 To UBound(tipo_modem)
  4566.  
  4567.                                 'SO SERA EXECUTADO SE NAO ACHAR
  4568.  
  4569.                                 tipo_modem(UBound(tipo_modem)).nome = modem
  4570.                                 tipo_modem(UBound(tipo_modem)).seq = 1
  4571.                                 ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
  4572.  
  4573.                                 'SO SERA EXECUTADO SE NAO ACHAR
  4574.  
  4575. encontrado_tipo_modem_pop:
  4576.  
  4577.  
  4578.                                 ReDim Preserve modens(UBound(modens) + 1)
  4579.  
  4580.                             End If    'If modem <> "CPU64" Then
  4581.  
  4582.                         End If  ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
  4583.  
  4584.  
  4585.  
  4586.                     Next    'For Each celula In Range(ciclo_pop(i))
  4587.  
  4588.                     For K = 0 To (UBound(modens) - 1)
  4589.  
  4590.                         nome_modem = modens(K).nome
  4591.                         cor_fonte_modem = modens(K).cor_fonte
  4592.  
  4593.                         For u = 0 To (UBound(tipo_modem) - 1)
  4594.  
  4595.                             If tipo_modem(u).nome = nome_modem Then
  4596.                                 seq_modem = tipo_modem(u).seq
  4597.                                 posicao_seq_modem = u
  4598.                                 Exit For
  4599.                             End If    'If tipo_modem(u).nome = nome_modem Then
  4600.  
  4601.                         Next    'For u = 0 To (UBound(tipo_modem) - 1)
  4602.  
  4603. 'VERIFICA SE O MODEM É UM MOFL4E1, AS PORTAS DELE SAO TRATADAS DE FORMA DIFERENTE
  4604.                        If nome_modem = "MOFL4E1" Then
  4605.  
  4606.                             seq_modem = Mid(Range("J" & modens(K).linha).Value, 1, 1)
  4607.  
  4608.                         End If
  4609.  
  4610.                         nome_modem_mod = nome_modem & "." & mux(i) & "." & seq_modem
  4611.  
  4612.                         If cor_fonte_modem = 0 Then
  4613.  
  4614.                             modens(K).novo_nome = nome_modem_mod
  4615.                             tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  4616.                             GoTo linha_zero_pop
  4617.  
  4618.                         End If    'If cor_fonte_modem = 0 Then
  4619.  
  4620.                         For y = 0 To (UBound(modens) - 1)
  4621.  
  4622.                             If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  4623.  
  4624.                                 modens(y).novo_nome = nome_modem_mod
  4625.  
  4626.  
  4627.                             End If    'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
  4628.  
  4629.  
  4630.                         Next    'For y = 0 To (UBound(modens) - 1)
  4631.  
  4632.                         tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
  4633. linha_zero_pop:
  4634.  
  4635.                         Range("I" & modens(K).linha).Value = nome_modem_mod
  4636. 'CASO O MODEM SEJA UM CABO_POP, CRIA UMA PORTA OTICA 1 PARA ELE PO1
  4637.                        If tipo_modem(posicao_seq_modem).nome = "CABO_POP" Then
  4638.  
  4639.                             Range("I" & modens(K).linha).Next.Value = "PO1"
  4640.  
  4641.                         End If    'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
  4642.  
  4643.                     Next    ' For k = 0 To UBound(modens)
  4644.  
  4645.                     For Each celula In Range(ciclo_pop(i))
  4646.  
  4647.                         linha_plan = celula.Row
  4648. 'VERIFICA SE A LINHA ACIMA DA LINHA ATUAL É PRETA E SE A PLANILHA É VESPER. EM CASO POSITIVO PEGA A SIGLA DO POP
  4649.                        If Range("C" & linha_plan - 1).Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
  4650.                             aba1 = Range("G" & linha_plan - 1).Value
  4651.                             sigla_pop = acha_sigla_pop(aba1)
  4652.                         End If
  4653. 'PEGA OS DADOS DA CELULA PARA GERAR O HYPERLINK
  4654.                        subend = ("'" & aba & "'!" & RemoveDolars(celula.Address))
  4655.                         'strcell = celula.Address
  4656.  
  4657.                         linha_preta = 0
  4658. 'RESETA AS VARIAVEIS QUE SAO UTILIZADAS QUANDO O MODEM É FLEX
  4659.                        nome_flex = ""
  4660.                         numero_flex = ""
  4661.                         slot_flex = ""
  4662.                         porta_flex = ""
  4663.  
  4664. 'VERIFICA SE A PORTA ESTÁ PREENCHIDA, SE A COR DA FONTE É DIFERENTE DE 0 E SE NÃO EXISTEM OS CARACTERES ESPECIAIS '-' E '/' NA PORTA
  4665.                        If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 And InStr(celula.Next.Value, "/") = 0 And InStr(celula.Next.Value, "-") = 0 Then
  4666. 'PEGA OS DADOS DAS PORTAS DO EQUIPAMENTO DO CLIENTE
  4667.                            porta_cliente = celula.Next.Value
  4668.                             cor_porta_cliente = celula.Next.Font.Color
  4669. 'VERIFICA SE A COR JÁ FOI UTILIZADA EM ALGUM MODEM ANTERIOR AO ATUAL
  4670.                            For K = 0 To (UBound(modens) - 1)
  4671.  
  4672.                                 If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  4673.  
  4674.                                     celula.Value = modens(K).novo_nome
  4675.  
  4676.                                 End If    'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
  4677.  
  4678.                             Next    'For k = 0 To (UBound(modens) - 1)
  4679. 'CASO A PORTA TENHA '/' OU '-' ELA É DE UM MODEM FLEX
  4680.                        ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") < 2 Then
  4681. 'SEPARA AS INFORMAÇÕES DA PORTA DO MODEM FLEX
  4682.                            celula.Select
  4683.                             celula.Next.Select
  4684.                             celula.Next.Font.Color = 0
  4685.                             nome_flex = "MOFL4E1"
  4686.                             numero_flex = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 2)
  4687.                             slot_flex = Mid(celula.Next.Value, 2, InStr(1, celula.Next.Value, "/") - 2)
  4688.                             porta_flex = "P" & Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
  4689.                             celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
  4690.  
  4691.  
  4692.                         ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") <> 0 And countSeparators(celula.Next.Value, "/") < 2 Then
  4693.  
  4694. 'CASO NAO SEJA UM MODEM FLEX, A PORTA É DE UM MODEM AX4E1
  4695.                            celula.Next.Value = UCase(RemoveSpaces((celula.Next.Value)))
  4696.                             celula.Next.Font.Color = 0
  4697.                             nome_flex = "MOAX4E1"
  4698.                             tira_mux = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "-") + 1, Len(celula.Next.Value))
  4699.                             numero_flex = Mid(tira_mux, 1, 1)
  4700.                             tira_numero = Mid(tira_mux, InStr(1, tira_mux, "S"), Len(tira_mux))
  4701.                             slot_flex = Mid(tira_numero, 1, InStr(1, tira_numero, "/") - 1)
  4702.                             tira_slot = Mid(tira_numero, InStr(1, tira_numero, "/") + 1, Len(tira_numero))
  4703.                             interface = Mid(tira_slot, 1, InStr(1, tira_slot, "P") - 1)
  4704.                             slot_flex = slot_flex & "/" & interface
  4705.                             porta_flex = Mid(tira_slot, InStr(1, tira_slot, interface) + 1, Len(tira_slot))
  4706.                             celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
  4707.  
  4708. 'CASO A PORTA NAO SEJA NEM DE UM MODEM FLEX, NEM DE UM AX4E1, É DE UM MDOEM DM4E1S
  4709.                        ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") = 2 Then
  4710.  
  4711.                             numero_dm4 = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 1)
  4712.                             slot_porta = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
  4713.  
  4714.                             celula.Value = "DM4E1S." & mux(i) & "." & numero_dm4
  4715.                             celula.Next.Value = "'" & slot_porta
  4716.  
  4717.  
  4718.                         End If    'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
  4719.  
  4720.  
  4721. 'AUMENTA EM 1 A CONTAGEM DA LINHA PRETA PARA O PROXIMO LOOP
  4722.                        If celula.Interior.ColorIndex = 1 Then
  4723.                             linha_preta = linha_preta + 1
  4724.                         End If
  4725.  
  4726.                         If Not IsEmpty(Range("L" & linha_plan).Value) And RemoveSpaces(Range("L" & linha_plan).Value) <> "" Then
  4727. 'PEGA O VALOR DA CELULA QUE CONTEM O SLOT
  4728.                            slot_plan = Range("L" & linha_plan).Value
  4729.  
  4730.                         End If
  4731.  
  4732.                         If Not IsEmpty(Range("K" & linha_plan).Value) And RemoveSpaces(Range("K" & linha_plan).Value) <> "" Then
  4733. 'PEGA O VALOR DA CELULA QUE CONTEM A PLACA
  4734.                            placa_plan = Range("K" & linha_plan).Value
  4735.  
  4736.                         End If
  4737. 'VERIFICA SE EXISTE UM CIRCUITO EXISTE E ESTE NÃO ESTÁ VAZIO
  4738.                        If Not IsEmpty(Range("C" & linha_plan).Value) And RemoveSpaces((Range("C" & linha_plan).Value)) <> "" Then
  4739.  
  4740.  
  4741.                             circuito_plan = Range("C" & linha_plan).Value
  4742.                             pop_mux_plan = sigla_pop
  4743.                             nome_mux_plan = mux(i)
  4744.                             tipo_mux_plan = acha_tipo_equip(nome_mux_plan)
  4745.                            
  4746.                             If tipo_mux_plan = "99" Then
  4747.                            
  4748.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(celula.Address))
  4749.                                 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, celula.Value, "Erro - Tipo de Multiplexador não identificado : " & nome_mux_plan)
  4750.                                vazia = 1
  4751.                            
  4752.                             End If
  4753.  
  4754.  
  4755.  
  4756.  
  4757. 'PEGA OS DADOS DA PORTA DO MUX - COLUNA M
  4758.                            If Not IsEmpty(Range("M" & linha_plan).Value) And RemoveSpaces(Range("M" & linha_plan).Value) <> "" Then
  4759.  
  4760.                                 porta_mux_plan = Range("M" & linha_plan).Value
  4761.  
  4762.                             Else
  4763.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("M" & linha_plan).Address))
  4764.                                 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("M" & linha_plan).Value, "Porta do Multiplexador não encontrada.")
  4765.                                vazia = 1
  4766.                            
  4767.                             End If
  4768. 'PEGA OS DADOS DO MODEM DO LADO DO POP
  4769.  
  4770.                             If Not IsEmpty(Range("I" & linha_plan).Value) And RemoveSpaces(Range("I" & linha_plan).Value) <> "" Then
  4771.  
  4772.                                 modem_pop_plan = Range("I" & linha_plan).Value
  4773.  
  4774.                                 tipo_modem_pop_plan = Mid(modem_pop_plan, 1, InStr(1, modem_pop_plan, ".") - 1)
  4775.  
  4776.                             Else
  4777. 'CASO ESTEJA VAZIO, CRIA-SE O CABO_POP
  4778.                                modem_pop_plan = "CABO_POP"
  4779.                                 tipo_modem_pop_plan = "CABO_POP"
  4780.  
  4781.                                 'VALIDA O TIPO DE MODEM DO LADO DO POP E CASO EXISTA, ADICIONA UM SEQUENCIAL A ELE
  4782.                                For t = 0 To UBound(tipo_modem)
  4783.  
  4784.                                     If tipo_modem(t).nome = modem_pop_plan Then
  4785.                                         tipo_modem(t).seq = tipo_modem(t).seq + 1
  4786.                                         seq_modem_vazio = tipo_modem(t).seq
  4787.                                         GoTo encontrado_tipo_modem_pop_vazio
  4788.                                     End If
  4789.  
  4790.                                 Next    'For t = 0 To UBound(tipo_modem)
  4791.  
  4792.                                 'SO SERA EXECUTADO SE NAO ACHAR
  4793. 'CRIA UM NOVO TIPO DE MODEM CASO NENHUM SEJA ENCONTRADO
  4794.                                tipo_modem(UBound(tipo_modem)).nome = modem_pop_plan
  4795.                                 tipo_modem(UBound(tipo_modem)).seq = 1
  4796.                                 seq_modem_vazio = 1
  4797.                                 ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
  4798.  
  4799.                                 'SO SERA EXECUTADO SE NAO ACHAR
  4800. encontrado_tipo_modem_pop_vazio:
  4801.  
  4802.                                 modem_pop_plan = modem_pop_plan & "." & mux(i) & "." & seq_modem_vazio
  4803.  
  4804.                             End If
  4805. 'CASO O MODEM SEJA FLEX OU AX4E1, A PORTA DO MODEM DO CLIENTE É A VARIAVEL 'slot_flex' E A PORTA DO LADO DO POP É PO1
  4806.                            If tipo_modem_pop_plan = "MOFL4E1" Or tipo_modem_pop_plan = "MOAX4E1" Then
  4807.  
  4808.                                 porta_modem_pop_cliente = slot_flex
  4809.                                 porta_modem_cliente_pop = "PO1"
  4810.  
  4811.                             Else
  4812. 'CASO CONTRARIO AMBAS AS PORTAS DO LADO DO CLIENTE E DO POP SÃO PORTAS OTICAS (PO1)
  4813.                                porta_modem_pop_cliente = "PO1"
  4814.                                 porta_modem_cliente_pop = "PO1"
  4815.  
  4816.  
  4817.                             End If
  4818. 'CASO NAO EXISTA UMA PORTA DE MODEM FLEX E A COLUNA J (PORTA DO LADO DO POP) NAO ESTEJA VAZIA,
  4819.                            If porta_flex = "" And Not IsEmpty(Range("J" & linha_plan).Value) And RemoveSpaces(Range("J" & linha_plan).Value) <> "" Then
  4820.  
  4821.                                 porta_pop_plan = Range("J" & linha_plan).Value
  4822. 'CASO EXISTA UMA PORTA FLEX, PEGA-SE O VALOR DELA
  4823.                            ElseIf porta_flex <> "" Then
  4824.  
  4825.                                 porta_pop_plan = porta_flex & "-" & slot_flex
  4826. 'CASO O MODEM SEJA CABO_POP, CRIA-SE A PORTA 'PE1'
  4827.                            ElseIf tipo_modem_pop_plan = "CABO_POP" Then
  4828.  
  4829.                                 porta_pop_plan = "PE1"
  4830.  
  4831.                             ElseIf tipo_modem_pop_plan = "CONV" Then
  4832.                                
  4833.                                 porta_pop_plan = "PE1"
  4834.                                    
  4835.                             Else
  4836.                            
  4837.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
  4838.                                 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do não modem(POP) encontrada.")
  4839.                                vazia = 1
  4840.  
  4841.                             End If
  4842. 'CASO O MODEM DO CLIENTE NAO ESTEJA VAZIO, PEGA OS DADOS DELE
  4843.                            If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" Then
  4844.  
  4845.                                 modem_cliente_plan = Range("E" & linha_plan).Value
  4846.                                 tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
  4847.                                
  4848.                             Else
  4849.                            
  4850.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("E" & linha_plan).Address))
  4851.                                 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("E" & linha_plan).Value, "Modem do cliente não encontrado.")
  4852.                                vazia = 1
  4853.      
  4854.  
  4855.                             End If
  4856. 'CASO O MODEM DO CLIENTE EXISTA E A COLUNA F NAO ESTEJA VAZIA, PEGA-SE OS DADOS DA PORTA DO CLIENTE DA COLUNA F
  4857.                            If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" And Not IsEmpty(Range("F" & linha_plan).Value) And RemoveSpaces(Range("F" & linha_plan).Value) <> "" Then
  4858.  
  4859.                                 porta_cli_plan = Range("F" & linha_plan).Value
  4860.  
  4861. 'CASO O MODEM SEJA CABO_CLI, CRIA-SE A PORTA 'P01'
  4862.                            ElseIf tipo_modem_cliente_plan = "CABO_CLI" Then
  4863.  
  4864.                                 porta_cli_plan = "PO1"
  4865.                                
  4866.                             ElseIf tipo_modem_cliente_plan = "CONV" Then
  4867.                            
  4868.                                 porta_cli_plan = "PE1"
  4869.                            
  4870.                             Else
  4871.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
  4872.                                 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do modem (CLI) não encontrada.")
  4873.                                vazia = 1
  4874.      
  4875.                             End If
  4876.  
  4877. 'CASO A COLUNA N ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OPERADORA DELA
  4878.                            If Not IsEmpty(Range("N" & linha_plan).Value) And RemoveSpaces(Range("N" & linha_plan).Value) <> "" Then
  4879.  
  4880.                                 operadora_plan = Range("N" & linha_plan).Value
  4881.  
  4882.                             End If
  4883. 'CASO A COLUNA O ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OS DELA
  4884.                            If Not IsEmpty(Range("O" & linha_plan).Value) And RemoveSpaces(Range("O" & linha_plan).Value) <> "" Then
  4885.  
  4886.                                 os_plan = Range("O" & linha_plan).Value
  4887.  
  4888.                             End If
  4889.  
  4890. 'CASO A COLUNA B ESTEJA PREENCHIDA, PEGA-SE OS DADOS DO STATUS DO CIRCUITO DELA
  4891.                            If Not IsEmpty(Range("B" & linha_plan)) And RemoveSpaces(Range("B" & linha_plan).Value) <> "" Then
  4892.                            
  4893.                                 status_circuito = Range("B" & linha_plan).Value
  4894.                                
  4895.                            Else
  4896.                                 subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("B" & linha_plan).Address))
  4897.                                 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("B" & linha_plan).Value, "Status do circuito não encontrado.")
  4898.                                vazia = 1
  4899.      
  4900.                            
  4901.                             End If
  4902.  
  4903.                         End If
  4904.                        
  4905. If modem_cliente_plan = "" Then
  4906.  
  4907. Windows(arquivo).Activate
  4908.  
  4909.     porta_mod_cli = Range("F" & linha_plan).Value
  4910.     cor_porta_mod_cli = Range("F" & linha_plan).Font.Color
  4911.     end_mod_cli = Range("H" & linha_plan).Value
  4912.     end_mod_cli = RemoveSpaces(UCase(end_mod_cli))
  4913.    
  4914.     If cor_porta_mod_cli <> 0 Then
  4915.    
  4916.    
  4917.         For Each celula_mod_cli In Range("C4:C" & LastRow)
  4918.        
  4919.             linha_mod_cli = celula_mod_cli.Row
  4920.            
  4921.             If (Range("F" & linha_mod_cli).Font.Color = cor_porta_mod_cli) And (end_mod_cli = RemoveSpaces(UCase(Range("H" & linha_mod_cli).Value))) And (linha_mod_cli <> linha_plan) Then
  4922.            
  4923.                 modem_cliente_plan = Range("E" & linha_mod_cli).Value
  4924.                 porta_cli_plan = porta_mod_cli
  4925.                 tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
  4926.                 Exit For
  4927.            
  4928.             End If
  4929.            
  4930.        
  4931.        
  4932.         Next 'For Each CELULA_MOD_CLI In Range("C4:C" & lastrow)
  4933.    
  4934.     End If
  4935.  
  4936. 'Windows(nova).Activate
  4937.  
  4938. End If
  4939.  
  4940.  
  4941.  
  4942.                     Next    'Each celula In Range(ciclo_pop(i))
  4943.  
  4944.                     ReDim modens(0)
  4945.                     ReDim tipo_modem(0)
  4946.  
  4947.                 Next    'For i = 0 To UBound(ciclo_pop)
  4948.  
  4949.  
  4950.  
  4951.             End If    '                If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  4952.            
  4953. 'AO FIM DE CADA ABA, VERIFICA SE HÁ A NECESSIDADE DE REORGANIZAR AS PORTAS DOS DM705
  4954.  
  4955.  
  4956.             rodada = 0
  4957.  
  4958.  
  4959.         Next    '            For Each sheet In ActiveWorkbook.Worksheets
  4960.        
  4961.         Windows(arquivo).Activate
  4962.        
  4963.        
  4964.        
  4965.        
  4966.    'FECHA O ARQUIVO DE FACILIDADES
  4967.  
  4968.        ' Windows(arquivo).Close False
  4969.  
  4970. '   Next    '        For sasa = LBound(Filename) To UBound(Filename)    ' FOR abre arquivos
  4971.  
  4972.  
  4973. 'VOLTA A ATUALIZAR A TELA
  4974.  
  4975.     'Application.ScreenUpdating = True
  4976.  
  4977. sicop = 0
  4978.  
  4979. End Function
  4980.  
  4981.  
  4982. Public Function letra_func(ByVal valor As String) As String
  4983.  
  4984. If Len(Trim(valor)) = 3 Then
  4985.  
  4986.     If InStr(1, valor, "A") <> 0 Then
  4987.    
  4988.     letra = Mid(valor, 1, 1)
  4989.    
  4990.     GoTo acha_letra
  4991.     End If
  4992.    
  4993.     If InStr(1, valor, "B") <> 0 Then
  4994.    
  4995.     letra = Mid(valor, 1, 1)
  4996.    
  4997.     GoTo acha_letra
  4998.     End If
  4999.    
  5000.     If InStr(1, valor, "C") <> 0 Then
  5001.    
  5002.     letra = Mid(valor, 1, 1)
  5003.    
  5004.     GoTo acha_letra
  5005.     End If
  5006.    
  5007.     If InStr(1, valor, "D") <> 0 Then
  5008.    
  5009.     letra = Mid(valor, 1, 1)
  5010.    
  5011.     GoTo acha_letra
  5012.     End If
  5013.    
  5014.     If InStr(1, valor, "E") <> 0 Then
  5015.    
  5016.     letra = Mid(valor, 1, 1)
  5017.    
  5018.     GoTo acha_letra
  5019.     End If
  5020.    
  5021.     If InStr(1, valor, "F") <> 0 Then
  5022.    
  5023.     letra = Mid(valor, 1, 1)
  5024.    
  5025.     GoTo acha_letra
  5026.     End If
  5027.    
  5028.     If InStr(1, valor, "G") <> 0 Then
  5029.    
  5030.     letra = Mid(valor, 1, 1)
  5031.    
  5032.     GoTo acha_letra
  5033.     End If
  5034.    
  5035.     If InStr(1, valor, "H") <> 0 Then
  5036.    
  5037.     letra = Mid(valor, 1, 1)
  5038.    
  5039.     GoTo acha_letra
  5040.     End If
  5041.    
  5042. End If
  5043.  
  5044.     letra = valor
  5045.    
  5046. acha_letra:
  5047.  
  5048.     letra_func = letra
  5049.  
  5050. End Function
  5051.  
  5052.  
  5053. Function checa_canalizado(ByVal velocidade As String) As Integer
  5054.  
  5055. velocidade = RemoveSpaces(UCase(velocidade))
  5056.  
  5057. Select Case (velocidade)
  5058.  
  5059.  
  5060.     Case "1M"
  5061.         checa_canalizado = 1
  5062.     Case "64K"
  5063.         checa_canalizado = 1
  5064.     Case "128K"
  5065.         checa_canalizado = 1
  5066.     Case "192K"
  5067.         checa_canalizado = 1
  5068.     Case "256K"
  5069.         checa_canalizado = 1
  5070.     Case "320K"
  5071.         checa_canalizado = 1
  5072.     Case "384K"
  5073.         checa_canalizado = 1
  5074.     Case "448K"
  5075.         checa_canalizado = 1
  5076.     Case "512K"
  5077.         checa_canalizado = 1
  5078.     Case "576K"
  5079.         checa_canalizado = 1
  5080.     Case "640K"
  5081.         checa_canalizado = 1
  5082.     Case "704K"
  5083.         checa_canalizado = 1
  5084.     Case "768K"
  5085.         checa_canalizado = 1
  5086.     Case "832K"
  5087.         checa_canalizado = 1
  5088.     Case "896K"
  5089.         checa_canalizado = 1
  5090.     Case "960K"
  5091.         checa_canalizado = 1
  5092.     Case "1024K"
  5093.         checa_canalizado = 1
  5094.     Case "1088K"
  5095.         checa_canalizado = 1
  5096.     Case "1152K"
  5097.         checa_canalizado = 1
  5098.     Case "1216K"
  5099.         checa_canalizado = 1
  5100.     Case "1280K"
  5101.         checa_canalizado = 1
  5102.     Case "1344K"
  5103.         checa_canalizado = 1
  5104.     Case "1408K"
  5105.         checa_canalizado = 1
  5106.     Case "1472K"
  5107.         checa_canalizado = 1
  5108.     Case "1536K"
  5109.         checa_canalizado = 1
  5110.     Case "1600K"
  5111.         checa_canalizado = 1
  5112.     Case "1664K"
  5113.         checa_canalizado = 1
  5114.     Case "1728K"
  5115.         checa_canalizado = 1
  5116.     Case "1792K"
  5117.         checa_canalizado = 1
  5118.     Case "1856K"
  5119.         checa_canalizado = 1
  5120.     Case "1920K"
  5121.         checa_canalizado = 1
  5122.     Case "1984K"
  5123.         checa_canalizado = 1
  5124.     Case Else
  5125.         checa_canalizado = 0
  5126.        
  5127. End Select
  5128.  
  5129. End Function
  5130.  
  5131. Public Function LastColumnInOneRow(ByVal linha As Integer) As String
  5132. 'Find the last used column in a Row: row 1 in this example
  5133.    Dim LastCol As Integer
  5134.     With ActiveSheet
  5135.         LastCol = .Cells(linha, .Columns.Count).End(xlToLeft).Column
  5136.     End With
  5137.     LastColumnInOneRow = LastCol
  5138. End Function
  5139.  
  5140. Public Function procura_next(ByVal prox_equip As String, ByVal coluna_atual As String, ByVal linha As Integer, ByVal ultima_coluna As String) As String
  5141.  
  5142.     For i = 3 To ultima_coluna
  5143.    
  5144.         If i Mod 2 = 1 Then
  5145.        
  5146.             coluna = ConvertToLetter(i)
  5147.            
  5148.             If coluna <> coluna_atual Then
  5149.            
  5150.                 facilidade = Range(ConvertToLetter(i) & linha).Value
  5151.                
  5152.                 comeco = Mid(facilidade, 1, InStr(1, facilidade, " ") - 1)
  5153.        
  5154.                 intermed = Mid(facilidade, InStr(1, facilidade, " ") + 1, Len(facilidade))
  5155.        
  5156.                 fim = Mid(intermed, 1, InStr(1, intermed, " ") - 1)
  5157.                
  5158.                 equip1 = Mid(comeco, 4, Len(comeco))
  5159.                 equip2 = Mid(fim, 4, Len(fim))
  5160.                
  5161.                 If InStr(1, equip1, prox_equip) <> 0 Then
  5162.                
  5163.                     procura_next = coluna & "." & equip2
  5164.                
  5165.                 ElseIf InStr(1, equip2, prox_equip) <> 0 Then
  5166.                    
  5167.                     procura_next = coluna & "." & equip1
  5168.                
  5169.                 End If
  5170.                    
  5171.            
  5172.             End If 'If coluna <> coluna_atual Then
  5173.        
  5174.        
  5175.         End If
  5176.    
  5177.     Next
  5178.  
  5179. If procura_next = "" Then
  5180.  
  5181.     procura_next = 0
  5182.  
  5183. End If
  5184.  
  5185. End Function
  5186.  
  5187. Public Function ordena_swap(array_canalizados() As String, ByVal linha As String) As Integer
  5188.  
  5189. Dim array_canal() As array_canal
  5190. ReDim Preserve array_canal(0)
  5191.  
  5192.  
  5193.  
  5194.     For i = 1 To UBound(array_canalizados)
  5195.    
  5196.         coluna_canal = array_canalizados(i - 1)
  5197.         coluna_ts = ConvertToLetter(ConvertToNumber(coluna_canal) + 1)
  5198.        
  5199.        
  5200.         array_canal(UBound(array_canal)).facilidade = Range(coluna_canal & linha).Value
  5201.         array_canal(UBound(array_canal)).ts = Range(coluna_ts & linha).Value
  5202.         ReDim Preserve array_canal(UBound(array_canal) + 1)
  5203.        
  5204.    
  5205.     Next
  5206.     j = 1
  5207.     For i = 1 To UBound(array_canal)
  5208.    
  5209.         coluna_insert_canal = ConvertToLetter(j + 2)
  5210.         coluna_insert_ts = ConvertToLetter(j + 3)
  5211.        
  5212.         Range(coluna_insert_canal & linha).Value = array_canal(i - 1).facilidade
  5213.         Range(coluna_insert_ts & linha).Value = "'" & array_canal(i - 1).ts
  5214.        
  5215.         j = j + 2
  5216.    
  5217.     Next
  5218.  
  5219.  
  5220. End Function
  5221.  
  5222. Function ConvertToNumber(ByVal Col As String) As Integer
  5223. 'Function ColRef(Col As String) As Integer
  5224.    Col = UCase(Col)
  5225.    
  5226.     If Len(Col) = 1 Then
  5227.         ConvertToNumber = Asc(Col) - 64
  5228.        
  5229.     ElseIf Len(Col) = 2 Then
  5230.         C1 = Left$(Col, 1)
  5231.         ColRef1 = (Asc(C1) - 64) * 26
  5232.        
  5233.         C2 = Right$(Col, 1)
  5234.         ConvertToNumber = ColRef1 + (Asc(C2) - 64)
  5235.     End If
  5236.    
  5237.  '   If (ConvertToNumber <> 256) Then
  5238. '       MsgBox "Wrong Column number", vbExclamation
  5239. '       ConvertToNumber = -1
  5240. '       Exit Function
  5241. '   End If
  5242.  
  5243. End Function
  5244.  
  5245.  
  5246. Public Type arrei
  5247.  
  5248.     cidade As String
  5249.     range1 As Integer
  5250.     range2 As Integer
  5251.     range3 As Integer
  5252.     range4 As Integer
  5253.     range5 As Integer
  5254.    
  5255.  
  5256. End Type
  5257. Dim conn As ADODB.Connection
  5258. Dim rs As ADODB.Recordset
  5259. Dim arrei() As arrei
  5260. Dim cancela As String
  5261.  
  5262. Private Sub ConnectDB()
  5263.     Set conn = New ADODB.Connection
  5264.     conn.Open "DRIVER={MySQL ODBC 5.2 ANSI Driver};" & _
  5265.                  "SERVER=mysql.infovias.unix.corp;" & _
  5266.                  "DATABASE=sici;" & _
  5267.                  "USER=sici;" & _
  5268.                  "PASSWORD=sici;" & _
  5269.                  "Option=3"
  5270.  
  5271.  
  5272. End Sub
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278. Public Sub auto_open()
  5279.  
  5280.     Cells.Clear
  5281.  
  5282.     Set rs = New ADODB.Recordset
  5283.    
  5284.     ConnectDB
  5285.    
  5286. '    GoTo formulario '###DEBUG
  5287.  
  5288.    
  5289.  
  5290.     rs.ActiveConnection = conn
  5291.     rs.LockType = adLockOptimistic
  5292.     rs.CursorLocation = adUseClient
  5293.     rs.CursorType = adOpenDynamic
  5294.  
  5295.  
  5296.     Dim sheet As Worksheet
  5297.     Dim celula, celula1 As Range
  5298.     Dim LastRow As Long
  5299.  
  5300.     Dim Filter As String
  5301.     Dim FilterIndex As Integer
  5302.     Dim Filename As Variant
  5303.     Dim remove As String
  5304.  
  5305.    
  5306.     ReDim Preserve arrei(0)
  5307.    
  5308. '    UserForm1.ComboBox1.List = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
  5309. '    UserForm1.ComboBox2.List = Array("2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020")
  5310. '    UserForm1.Show
  5311. '
  5312. '    If UserForm1.Label2.Caption = "Cancelado" Then
  5313. '        retorno_user = MsgBox("Processo cancelado!", , "INFO")
  5314. '        UserForm1.Label2.Caption = ""
  5315. '        UserForm1.ComboBox1.Value = ""
  5316. '        UserForm1.ComboBox2.Value = ""
  5317. '        Exit Sub
  5318. '    End If
  5319. '
  5320. '    select_envio = "select id_envio from sici_envio where referencia_mes = '" & CInt(UserForm1.ComboBox1.Value) & "' and referencia_ano = '" & CInt(UserForm1.ComboBox2.Value) & "'"
  5321. '    rs.Open select_envio, conn
  5322. '
  5323. '    If rs.BOF = False Then
  5324. '
  5325. '        competencia = UserForm1.ComboBox1.Value & " / " & UserForm1.ComboBox2.Value
  5326. '        pergunta = MsgBox("Já existem informações no banco da competência " & competencia & ". Deseja SOBRESCREVER?", vbYesNo, "Confirma?")
  5327. '
  5328. '        If pergunta = vbYes Then
  5329. '            id_envio = rs!id_envio
  5330. '            rs.Close
  5331. '            delete_cidade_envio = "delete from sici_cidade_envio where id_envio = " & id_envio
  5332. '            rs.Open delete_cidade_envio, conn
  5333. '            delete_indicador_item = "delete from sici_indicador_item where id_envio = " & id_envio
  5334. '            rs.Open delete_indicador_item, conn
  5335. '
  5336. '        Else
  5337. '            retorno_user = MsgBox("Processo cancelado!", , "INFO")
  5338. '            Exit Sub
  5339. '        End If
  5340. '
  5341. '        If rs.State = adStateOpen Then
  5342. '            rs.Close
  5343. '        End If
  5344. '
  5345. '
  5346. '    Else
  5347. '        rs.Close
  5348. '        insert_envio = "insert into sici_envio values (''," & CInt(UserForm1.ComboBox1.Value) & "," & CInt(UserForm1.ComboBox2.Value) & ",'',null)"
  5349. '        rs.Open insert_envio, conn
  5350. '        select_id_envio = "select max(id_envio) as id_envio from sici_envio"
  5351. '        rs.Open select_id_envio, conn
  5352. '        id_envio = rs!id_envio
  5353. '        rs.Close
  5354. '
  5355. '    End If
  5356.  
  5357.     Application.ScreenUpdating = False
  5358.  
  5359.  
  5360.     ' File filters
  5361.    Filter = "Excel Files (*.xls),*.xls," & _
  5362.              "Text Files (*.txt),*.txt," & _
  5363.              "All Files (*.*),*.*"
  5364.     '   Default filter to *.*
  5365.    FilterIndex = 3
  5366.     ' Set Dialog Caption
  5367.    Title = "Favor selecionar os arquivos do controle de facilidades "
  5368.     ' Select Start Drive & Path
  5369.    ChDrive ("C")
  5370.     ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia\Facilidades")
  5371.     With Application
  5372.         ' Set File Name Array to selected Files (allow multiple)
  5373.        Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
  5374.         ' Reset Start Drive/Path
  5375.        ChDrive (Left(.DefaultFilePath, 1))
  5376.         ChDir (.DefaultFilePath)
  5377.     End With
  5378.     ' Exit on Cancel
  5379.  
  5380.     If Not IsArray(Filename) Then
  5381.         MsgBox "Nenhum arquivo selecionado."
  5382.         Exit Sub
  5383.     End If
  5384.  
  5385.     principal = ActiveWorkbook.Name
  5386.     '    Workbooks.Add
  5387.    '    ActiveWorkbook.Activate
  5388.    '    nova = ActiveWorkbook.Name
  5389.  
  5390.     ' Open Files
  5391.    For sasa = LBound(Filename) To UBound(Filename)    ' FOR abre arquivos
  5392.        msg = msg & Filename(sasa) & vbCrLf    ' This can be removed
  5393.        Workbooks.Open Filename(sasa), False
  5394.  
  5395.         arquivo = ActiveWorkbook.Name
  5396.         Windows(arquivo).Activate
  5397.  
  5398.         For Each sheet In ActiveWorkbook.Worksheets
  5399.  
  5400.             If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" And sheet.Name <> "Sites_Vesper" Then
  5401.  
  5402.                 sheet.Select
  5403.                 aba = sheet.Name
  5404.                
  5405.                 cidade = acha_cidade(aba)
  5406.  
  5407.                 If WorksheetFunction.CountA(Cells) > 0 Then
  5408.                     'Search for any entry, by searching backwards by Rows.
  5409.                    LastRow = Cells.Find(What:="*", After:=[A1], _
  5410.                                          SearchOrder:=xlByRows, _
  5411.                                          SearchDirection:=xlPrevious).Row
  5412.  
  5413.                 End If
  5414.  
  5415.                 For Each celula In Range("C4:C" & LastRow)
  5416.  
  5417.                     If Not IsEmpty(celula.Value) And RemoveSpaces(celula.Value) <> "" And celula.Interior.ColorIndex <> 1 Then
  5418.                    
  5419.                         linha = celula.Row
  5420.                        
  5421.                         designacao = Range("C" & linha).Value
  5422.                         velocidade = Range("D" & linha).Value
  5423.                        
  5424.                         Select Case velocidade
  5425.                         Case "2M"
  5426.                             retorno = insere_velo(cidade, 2)
  5427.                         Case "0"
  5428.                             retorno = insere_velo(cidade, 6)
  5429.                         Case "1"
  5430.                             retorno = insere_velo(cidade, 6)
  5431.                         Case "2"
  5432.                             retorno = insere_velo(cidade, 6)
  5433.                         Case "3"
  5434.                             retorno = insere_velo(cidade, 6)
  5435.                         Case "4"
  5436.                             retorno = insere_velo(cidade, 6)
  5437.                         Case "5"
  5438.                             retorno = insere_velo(cidade, 6)
  5439.                         Case "6"
  5440.                             retorno = insere_velo(cidade, 6)
  5441.                         Case "7"
  5442.                             retorno = insere_velo(cidade, 6)
  5443.                         Case "8"
  5444.                             retorno = insere_velo(cidade, 6)
  5445.                         Case "9"
  5446.                             retorno = insere_velo(cidade, 6)
  5447.                         Case "10"
  5448.                             retorno = insere_velo(cidade, 6)
  5449.                         Case "11"
  5450.                             retorno = insere_velo(cidade, 6)
  5451.                         Case "12"
  5452.                             retorno = insere_velo(cidade, 6)
  5453.                         Case "13"
  5454.                             retorno = insere_velo(cidade, 6)
  5455.                         Case "14"
  5456.                             retorno = insere_velo(cidade, 6)
  5457.                         Case "16"
  5458.                             retorno = insere_velo(cidade, 6)
  5459.                         Case "17"
  5460.                             retorno = insere_velo(cidade, 6)
  5461.                         Case "18"
  5462.                             retorno = insere_velo(cidade, 6)
  5463.                         Case "19"
  5464.                             retorno = insere_velo(cidade, 6)
  5465.                         Case "20"
  5466.                             retorno = insere_velo(cidade, 6)
  5467.                         Case "21"
  5468.                             retorno = insere_velo(cidade, 6)
  5469.                         Case "22"
  5470.                             retorno = insere_velo(cidade, 6)
  5471.                         Case "26"
  5472.                             retorno = insere_velo(cidade, 6)
  5473.                         Case "27"
  5474.                             retorno = insere_velo(cidade, 6)
  5475.                         Case "29"
  5476.                             retorno = insere_velo(cidade, 6)
  5477.                         Case "30"
  5478.                             retorno = insere_velo(cidade, 6)
  5479.                         Case "44"
  5480.                             retorno = insere_velo(cidade, 6)
  5481.                         Case "54"
  5482.                             retorno = insere_velo(cidade, 6)
  5483.                         Case "57"
  5484.                             retorno = insere_velo(cidade, 6)
  5485.                         Case "58"
  5486.                             retorno = insere_velo(cidade, 6)
  5487.                         Case "59"
  5488.                             retorno = insere_velo(cidade, 6)
  5489.                         Case "100M"
  5490.                             retorno = insere_velo(cidade, 5)
  5491.                         Case "10M"
  5492.                             retorno = insere_velo(cidade, 3)
  5493.                         Case "128K"
  5494.                             retorno = insere_velo(cidade, 1)
  5495.                         Case "155M"
  5496.                             retorno = insere_velo(cidade, 5)
  5497.                         Case "1984K"
  5498.                             retorno = insere_velo(cidade, 2)
  5499.                         Case "1M"
  5500.                             retorno = insere_velo(cidade, 2)
  5501.                         Case "20M"
  5502.                             retorno = insere_velo(cidade, 4)
  5503.                         Case "256K"
  5504.                             retorno = insere_velo(cidade, 1)
  5505.                         Case "256k "
  5506.                             retorno = insere_velo(cidade, 1)
  5507.                         Case "2M"
  5508.                             retorno = insere_velo(cidade, 2)
  5509.                         Case "2M "
  5510.                             retorno = insere_velo(cidade, 2)
  5511.                         Case "32M"
  5512.                             retorno = insere_velo(cidade, 4)
  5513.                         Case "34M"
  5514.                             retorno = insere_velo(cidade, 4)
  5515.                         Case "40M"
  5516.                             retorno = insere_velo(cidade, 5)
  5517.                         Case "45M"
  5518.                             retorno = insere_velo(cidade, 5)
  5519.                         Case "48M"
  5520.                             retorno = insere_velo(cidade, 5)
  5521.                         Case "4M"
  5522.                             retorno = insere_velo(cidade, 3)
  5523.                         Case "50M"
  5524.                             retorno = insere_velo(cidade, 5)
  5525.                         Case "512K"
  5526.                             retorno = insere_velo(cidade, 1)
  5527.                         Case "5M"
  5528.                             retorno = insere_velo(cidade, 3)
  5529.                         Case "64K"
  5530.                             retorno = insere_velo(cidade, 1)
  5531.                         Case "6M"
  5532.                             retorno = insere_velo(cidade, 3)
  5533.                         Case "768K"
  5534.                             retorno = insere_velo(cidade, 2)
  5535.                         Case "80M"
  5536.                             retorno = insere_velo(cidade, 5)
  5537.                         Case "84M"
  5538.                             retorno = insere_velo(cidade, 5)
  5539.                         Case "8M"
  5540.                             retorno = insere_velo(cidade, 3)
  5541.                         Case "960k"
  5542.                             retorno = insere_velo(cidade, 1)
  5543.                         End Select
  5544.                        
  5545.                         Windows(principal).Activate
  5546.                        
  5547.                         If WorksheetFunction.CountA(Cells) > 0 Then
  5548.                             'Search for any entry, by searching backwards by Rows.
  5549.                            LastRow3 = Cells.Find(What:="*", After:=[A1], _
  5550.                                                  SearchOrder:=xlByRows, _
  5551.                                                  SearchDirection:=xlPrevious).Row
  5552.        
  5553.                         End If
  5554.                        
  5555.                         Range("A" & LastRow3 + 1).Value = designacao
  5556.                         Range("B" & LastRow3 + 1).Value = velocidade
  5557.                         Range("C" & LastRow3 + 1).Value = cidade
  5558.                        
  5559.                         Windows(arquivo).Activate
  5560.                                
  5561.                        
  5562.                    
  5563.                     End If '                    If Not IsEmpty(celula.Value) And RemoveSpaces(celula.Value) <> "" Then
  5564.  
  5565.                 Next    '                    For Each celula In Range("A3:A" & LastRow)
  5566.  
  5567.  
  5568.             End If    '                If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
  5569.  
  5570.         Next    '            For Each sheet In ActiveWorkbook.Worksheets
  5571.  
  5572.         Windows(arquivo).Close False
  5573.  
  5574.     Next    '        For sasa = LBound(Filename) To UBound(Filename)    ' FOR abre arquivos
  5575.  
  5576.  
  5577.     Windows(principal).Activate
  5578.    
  5579.     Application.ScreenUpdating = True
  5580.    
  5581.  
  5582. End Sub
  5583. Public Function insere_velo(ByVal cidade As String, ByVal posicao As Integer)
  5584.  
  5585. If posicao = 6 Then
  5586.    
  5587.         Exit Function
  5588.  
  5589. End If
  5590.  
  5591. Achou = 0
  5592.  
  5593. For i = 0 To UBound(arrei)
  5594.  
  5595.     If arrei(i).cidade = cidade Then
  5596.         Select Case posicao
  5597.             Case 1
  5598.                 arrei(i).range1 = arrei(i).range1 + 1
  5599.                 Exit Function
  5600.             Case 2
  5601.                 arrei(i).range2 = arrei(i).range2 + 1
  5602.                 Exit Function
  5603.             Case 3
  5604.                 arrei(i).range3 = arrei(i).range3 + 1
  5605.                 Exit Function
  5606.             Case 4
  5607.                 arrei(i).range4 = arrei(i).range4 + 1
  5608.                 Exit Function
  5609.             Case 5
  5610.                 arrei(i).range5 = arrei(i).range5 + 1
  5611.                 Exit Function
  5612.         End Select
  5613.         Achou = 1
  5614.     End If
  5615.  
  5616. Next
  5617.  
  5618. If Achou = 0 Then
  5619.  
  5620. arrei(UBound(arrei)).cidade = cidade
  5621.  
  5622. Select Case posicao
  5623.     Case 1
  5624.         arrei(UBound(arrei)).range1 = 1
  5625.     Case 2
  5626.         arrei(UBound(arrei)).range2 = 1
  5627.     Case 3
  5628.         arrei(UBound(arrei)).range3 = 1
  5629.     Case 4
  5630.         arrei(UBound(arrei)).range4 = 1
  5631.     Case 5
  5632.         arrei(UBound(arrei)).range5 = 1
  5633. End Select
  5634.  
  5635. ReDim Preserve arrei(UBound(arrei) + 1)
  5636.  
  5637. End If
  5638.  
  5639.  
  5640. End Function
  5641.  
  5642. Public Function acha_cidade(ByVal plan As String)
  5643.  
  5644. If rs.State = adStateOpen Then
  5645.     rs.Close
  5646. End If
  5647.  
  5648. select_plan = "select c.nome_cidade as nome from pop p join cidade c on p.id_cidade = c.id_cidade where p.nome_pop = '" & plan & "'"
  5649. rs.Open select_plan
  5650.  
  5651. If rs.BOF = False Then
  5652.  
  5653.     acha_cidade = rs!nome
  5654.     rs.Close
  5655.  
  5656. Else
  5657.  
  5658.     MsgBox (plan)
  5659.  
  5660. End If
  5661.  
  5662. End Function
  5663.  
  5664. Public Function RemoveSpaces(strInput As String)
  5665. ' Removes all spaces from a string of text
  5666. Test:
  5667.     If InStr(strInput, " ") = 0 Then
  5668.         RemoveSpaces = strInput
  5669.     Else
  5670.         strInput = Left(strInput, InStr(strInput, " ") - 1) _
  5671.                    & Right(strInput, Len(strInput) - InStr(strInput, " "))
  5672.         GoTo Test
  5673.     End If
  5674. End Function
  5675.  
  5676. Public Function checa_cor(linha As Integer, coluna As Integer)
  5677.  
  5678.     If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
  5679.         checa_cor = 0
  5680.  
  5681.     Else
  5682.  
  5683.         checa_cor = 1
  5684.  
  5685.     End If    'If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
  5686.  
  5687. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement