- 15 Out 2019 às 12:56
#49239
Tenho a seguinte macro:
Código: Selecionar todos
Gostaria de alterar toda essa parte que fala da linha 400 para a ultima linha preenchida+1[size=85][b][i]Sub Dados_Resumo2()
'
' Dados_Resumo2 Macro
'
'
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Range("B2").Select
ActiveCell.FormulaR1C1 = "OS"
Range("C2").Select
ActiveCell.FormulaR1C1 = "DATA"
Range("D2").Select
ActiveCell.FormulaR1C1 = "RECEBIDO"
Range("E2").Select
ActiveCell.FormulaR1C1 = "A RECEBER"
Range("F2").Select
ActiveCell.FormulaR1C1 = "A COBRAR"
Range("G2").Select
ActiveCell.FormulaR1C1 = "NOTA FISCAL"
Range("H2").Select
ActiveCell.FormulaR1C1 = "EMISSÃO NOTA"
Range("B3").Select
Sheets("Base OS").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveSheet.Previous.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Range("D2").Select
ActiveCell.FormulaR1C1 = "FATURADO"
Range("C3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'Base OS'!C[-2]:C[4],7,0)"
Range("D3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2],'Base OS'!C[-3]:C[-2],2,0)"
Range("E3").Select
ActiveCell.FormulaR1C1 = _
"=SUMIFS('Contas a Receber'!C[10],'Contas a Receber'!C[11],""RECEBIDO"",'Contas a Receber'!C[-4],'Resumo Analitico'!RC[-3])"
Range("F3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=SUMIFS('Contas a Receber'!C[7],'Contas a Receber'!C[10],""A RECEBER"",'Contas a Receber'!C[-5],'Resumo Analitico'!RC[-4])"
Range("G3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-5],'Base OS'!C[-6]:C[-3],4,0)"
Range("H3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-6],'Base OS'!C[-7]:C[-3],5,0)"
Range("I3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-7],'Base OS'!C[-8]:C[-3],6,0)"
Range("C3:I3").Select
Range("I3").Activate
Selection.Copy
Range("I4").Select
Selection.End(xlToLeft).Select
Selection.End(xlDown).Select
Range("C399").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Replace What:="#N/D", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("C400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "TOTAL"
Range("D400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-37]C:R[-1]C)"
Range("E400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-37]C:R[-1]C)"
Range("F400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-37]C:R[-1]C)"
Range("F400").Select
Selection.Copy
Range("G400").Select
Selection.End(xlToRight).Select
Selection.End(xlToRight).Select
Selection.End(xlUp).Select
Range("G2").Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Bold = True
Range(Selection, Selection.End(xlDown)).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 = xlContinuous
.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
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C3").Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
Range("C3").Select
Range(Selection, Selection.End(xlDown)).Select
Range("C3:C399").Select
Selection.NumberFormat = "dd/mm/yyyy"
Range("D3").Select
Range(Selection, Selection.End(xlDown)).Select
Range("D3:G400").Select
Selection.Style = "Currency"
Selection.End(xlUp).Select
Range("B2").Select
Selection.End(xlDown).Select
Range("B400:C400").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Bold = True
Range(Selection, Selection.End(xlToRight)).Select
Range("B400:I400").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 = xlContinuous
.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
Range("D26").Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Columns("H:H").Select
Columns("H:H").EntireColumn.AutoFit
Columns("I:I").EntireColumn.AutoFit
Range("H2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Sheets("Base OS").Select
Columns("A:G").Select
Range("G1").Activate
Selection.Delete Shift:=xlToLeft
Range("B2").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("B1").Select
ActiveCell.FormulaR1C1 = "COLAR AQUI"
Range("B2").Select
Columns("B:B").EntireColumn.AutoFit
Range("B1").Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
ActiveSheet.Previous.Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
End Sub[/i][/b][/size]
Código: Selecionar todos
E essa parte que fala da linha 399 gostaria de alterar para a ultima linha preenchida: Range("C400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "TOTAL"
Range("D400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-37]C:R[-1]C)"
Range("E400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-37]C:R[-1]C)"
Range("F400").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-37]C:R[-1]C)"
Range("F400").Select
Selection.Copy
Range("G400").Select
Código: Selecionar todos
Selection.End(xlToLeft).Select
Selection.End(xlDown).Select
Range("C399").Select