Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Macro4()
- '
- ' Criar tabela com requisições por ot
- '
- ' Atalho por teclado: Ctrl+q
- '
- Dim tamanho As Variant
- Dim l
- Dim folder As Variant
- Dim d_ot As Range
- Dim i_ot As Range
- Dim req As Range
- Dim caminho
- Dim file As Variant
- Dim custo_est As Range
- 'Const partilha = "F:\RQ\"
- Const partilha = "\\Path\EM_TRATAMENTO\"
- Range("A16:e500").Clear
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- Selection.Borders(xlEdgeLeft).LineStyle = xlNone
- Selection.Borders(xlEdgeTop).LineStyle = xlNone
- Selection.Borders(xlEdgeBottom).LineStyle = xlNone
- Selection.Borders(xlEdgeRight).LineStyle = xlNone
- Selection.Borders(xlInsideVertical).LineStyle = xlNone
- Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
- With CreateObject("Scripting.FileSystemObject")
- Set req = ActiveSheet.Cells(16, 1)
- Set d_ot = ActiveSheet.Cells(16, 2)
- Set i_ot = ActiveSheet.Cells(16, 3)
- Set custo_est = ActiveSheet.Cells(16, 4)
- Set c = ActiveSheet.Cells(10, 7)
- tamanho = Range("I65536").End(xlUp).Row
- For l = 3 To tamanho
- folder = ActiveSheet.Cells(l, 9)
- caminho = partilha & folder
- For Each file In .GetFolder(caminho).Files
- If LCase(Left(.GetExtensionName(file.Name), 3)) = "xls" Then
- If Right(.GetBaseName(file), 3) = "REQ" Then
- req.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$A$6"
- Set req = req.Offset(1)
- d_ot.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$B$9"
- Set d_ot = d_ot.Offset(1)
- i_ot.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$B$10"
- Set i_ot = i_ot.Offset(1)
- custo_est.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$F$58"
- Set custo_est = custo_est.Offset(1)
- End If
- End If
- Next
- Next l
- tamanho = Range("A65536").End(xlUp).Row
- For l = tamanho To 16 Step -1
- c = ActiveSheet.Cells(l, 4)
- If c = 0 Then
- Range(Cells(l, 1), Cells(l, 4)).Clear
- Worksheets("Folha1").Range(Cells(16, 1), Cells(tamanho, 5)).Sort Key1:=Worksheets("Folha1").Columns("A"), Order1:=xlAscending
- End If
- Next l
- tamanho = Range("A600").End(xlUp).Row
- Range(Cells(16, 1), Cells(tamanho, 4)).Select
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlInsideVertical)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideHorizontal)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- tamanho = tamanho + 2
- Range(Cells(tamanho, 3), Cells(tamanho, 3)).Select
- With Selection
- .HorizontalAlignment = xlRight
- .VerticalAlignment = xlBottom
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = True
- End With
- ActiveCell.FormulaR1C1 = "Total Estimado:"
- Range(Cells(tamanho, 4), Cells(tamanho, 4)).Select
- ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Sum(Range(Cells(16, 4), Cells(tamanho, 4)))
- Range(Cells(tamanho, 4), Cells(tamanho, 4)).Select
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThick
- End With
- 'Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
- Selection.NumberFormat = "#,##0.00 $"
- Range(Cells(3, 8), Cells(53, 10)).Interior.ColorIndex = 43
- Range(Cells(3, 9), Cells(52, 9)).Interior.ColorIndex = 19
- Range(Cells(3, 9), Cells(52, 9)).Select
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlDouble
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideVertical)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideHorizontal)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- 'Worksheets("Folha1").Range(Cells(16, 1), Cells(tamanho, 5)).Sort Key1:=Worksheets("Folha1").Columns("E"), Order1:=xlAscending
- 'Range("A1").Activate
- Application.GoTo Reference:=Worksheets("Folha1").Range("A1"), scroll:=True
- End With
- End Sub
- 'https://lh6.googleusercontent.com/-LJy4bPrI_kM/TmecErTbz0I/AAAAAAAAA70/zkXmMgLCvmY/s1055/prioridades_1.jpg
- 'https://lh4.googleusercontent.com/-ymTWrsBl-4I/TmecHF9yz9I/AAAAAAAAA78/w04rtVAezTc/s1055/prioridades_2.jpg
Advertisement
Add Comment
Please, Sign In to add comment