Coding certain cells a color - vba

How do I code something to say: If the total amount is under $1000 (E11:E28) then it will turn red? Also, is there a way to clean up this vba so that it's no so lengthy?
This is a project that I want to teach my students to do as a way to do some basic budgeting.
Here is my current code:
Sub ClassroomSupplies()
Range("A7").Select
ActiveCell.FormulaR1C1 = "Week of July 2-6, 2018"
Range("A10").Select
Columns("B:B").ColumnWidth = 9.57
Range("A8:B8").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("A10").Select
ActiveCell.FormulaR1C1 = "AMOUNT"
Range("B10").Select
ActiveCell.FormulaR1C1 = "SALES"
Range("C10").Select
ActiveCell.FormulaR1C1 = "PRICE PER UNIT"
Range("D10").Select
ActiveCell.FormulaR1C1 = "TAX"
Range("E10").Select
ActiveCell.FormulaR1C1 = "TOTAL"
Range("A11").Select
ActiveCell.FormulaR1C1 = "Calculators"
Range("A12").Select
ActiveCell.FormulaR1C1 = "Pencils"
Range("A13").Select
ActiveCell.FormulaR1C1 = "Loose Leaf Paper"
Range("A14").Select
ActiveCell.FormulaR1C1 = "Balloons"
Range("A15").Select
ActiveCell.FormulaR1C1 = "Mirrors"
Range("A16").Select
ActiveCell.FormulaR1C1 = "Axles"
Range("A17").Select
ActiveCell.FormulaR1C1 = "Wheels"
Range("A18").Select
ActiveCell.FormulaR1C1 = "Masking Tape"
Range("A19").Select
ActiveCell.FormulaR1C1 = "Electrical Tape"
Range("A20").Select
ActiveCell.FormulaR1C1 = "Mini Blocks"
Range("A21").Select
ActiveCell.FormulaR1C1 = "Tongue Depressors"
Range("A22").Select
ActiveCell.FormulaR1C1 = "Slinkys"
Range("A23").Select
ActiveCell.FormulaR1C1 = "Beakers"
Range("A24").Select
ActiveCell.FormulaR1C1 = "Test Tubes"
Range("A25").Select
ActiveCell.FormulaR1C1 = "Colored Pencils"
Range("A26").Select
ActiveCell.FormulaR1C1 = "Lenses"
Range("A27").Select
ActiveCell.FormulaR1C1 = "Newspapers"
Range("A28").Select
ActiveCell.FormulaR1C1 = "Cardboard"
Range("B11").Select
ActiveCell.FormulaR1C1 = "10392"
Range("B12").Select
ActiveCell.FormulaR1C1 = "10788"
Range("B13").Select
ActiveCell.FormulaR1C1 = "15588"
Range("B14").Select
ActiveCell.FormulaR1C1 = "1188"
Range("B15").Select
ActiveCell.FormulaR1C1 = "5970"
Range("B16").Select
ActiveCell.FormulaR1C1 = "8970"
Range("B17").Select
ActiveCell.FormulaR1C1 = "7980"
Range("B18").Select
ActiveCell.FormulaR1C1 = "5990"
Range("B19").Select
ActiveCell.FormulaR1C1 = "2970"
Range("B20").Select
ActiveCell.FormulaR1C1 = "4788"
Range("B21").Select
ActiveCell.FormulaR1C1 = "3192"
Range("B22").Select
ActiveCell.FormulaR1C1 = "6487"
Range("B23").Select
ActiveCell.FormulaR1C1 = "490"
Range("B24").Select
ActiveCell.FormulaR1C1 = "490"
Range("B25").Select
ActiveCell.FormulaR1C1 = "15684"
Range("B26").Select
ActiveCell.FormulaR1C1 = "80"
Range("B27").Select
ActiveCell.FormulaR1C1 = "100"
Range("B28").Select
ActiveCell.FormulaR1C1 = "95"
Range("B29").Select
Range("C11:C28").Select
Selection.Style = "Currency"
Range("D11").Select
ActiveCell.FormulaR1C1 = "=SUM((RC[-2]*RC[-1])*0.0625)"
Range("D11").Select
Selection.AutoFill Destination:=Range("D11:D28"), Type:=xlFillDefault
Range("D11:D28").Select
Selection.Style = "Currency"
Range("E11").Select
ActiveCell.FormulaR1C1 = "=SUM((RC[-3]*RC[-2])+RC[-1])"
Range("E11").Select
Selection.AutoFill Destination:=Range("E11:E28"), Type:=xlFillDefault
Range("E11:E28").Select
Range("E31").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-20]C:R[-3]C)"
ActiveCell.FormulaR1C1 = "=SUM(R[-20]C:R[-3]C)"
Range("E34").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-3]C/5)"
Range("E35").Select
End Sub
Any help would be greatly appreciated.
Thanks!

Try,
'this to set a conditional formatting rule on E11:E28
with range("E11:E28")
.FormatConditions.Delete
With .FormatConditions.Add(Type:=xlExpression, Formula1:="=and(len($e11), $e11<1000)")
.Interior.Color = vbred
End With
end with
'this should get you started cleaning up the text labels
Range("A10:E10") = array("AMOUNT","SALES","PRICE PER UNIT","TAX","TOTAL")
Range("A11:A28") = application.transpose(array("Calculators","Pencils","Loose Leaf Paper", _
"Balloons","Mirrors","Axles","Wheels","Masking Tape", _
"Electrical Tape","Mini Blocks","Tongue Depressors", _
"Slinkys","Beakers","Test Tubes","Colored Pencils", _
"Lenses","Newspapers","Cardboard"))
Note that filling in a number of columns in a single row only requires passing the array into the range but to fill in a number of rows in a single column you must Transpose the array.
Please read How to avoid using Select in Excel VBA.

Related

Use a Macro on a list of information. New worksheet needed for each row of information

I'm new to all this Macro thing and haven't used before, so could do with a bit of help.
I've set up a Macro to create a new Quote from a template and list of information. I have a sheet named Summery which includes customer information etc and all of this info is needed to be added to the quote template. I have created a basic Macro and it does the job but I now need it to do the same for each customer listed. At the moment it only runs on the first row.
Please can someone assist in what code I need to use for it to run on the entire list of customers?
Sub Macro2()
'
' Macro2 Macro
' Create New Quote for each customer
'
' Keyboard Shortcut: Ctrl+q
Sheets("Master").Select
Sheets("Master").Copy After:=Sheets(2)
Range("A13").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-9]C[1]"
Range("A15").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-11]C[2]"
Range("E13").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-9]C[-1]"
Range("E15").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-11]C"
Range("B19").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-15]C[5]"
Range("B20").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-16]C[6]"
Range("B21").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-17]C[7]"
Range("B22").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-18]C[8]"
Range("B23").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-19]C[9]"
Range("B24").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-20]C[10]"
Range("B25").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-21]C[11]"
Range("B26").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-22]C[12]"
Range("B27").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-23]C[13]"
Range("B28").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-24]C[14]"
Range("B30").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-26]C[15]"
Range("B31").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-27]C[16]"
Range("B32").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-28]C[17]"
Range("B33").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-29]C[18]"
Range("B34").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-30]C[19]"
Range("B35").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-31]C[20]"
Range("B36").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-32]C[21]"
Range("B37").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-33]C[22]"
Range("B38").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-34]C[23]"
Range("B39").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-35]C[24]"
Range("A40:D40").Select
ActiveWindow.SmallScroll Down:=9
Range("B41").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-37]C[25]"
Range("B42").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-38]C[26]"
Range("B43").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-39]C[27]"
Range("B45").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-41]C[28]"
Range("B47").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-43]C[29]"
Range("B48").Select
ActiveWindow.SmallScroll Down:=-9
Range("C19").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-15]C[30]"
Range("C20").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-16]C[31]"
Range("C21").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-17]C[32]"
Range("C22").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-18]C[33]"
Range("C23").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-19]C[34]"
Range("C24").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-20]C[35]"
Range("C25").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-21]C[36]"
Range("C26").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-22]C[37]"
Range("C27").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-23]C[38]"
Range("C28").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-24]C[39]"
Range("C30").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-26]C[40]"
Range("C31").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-27]C[41]"
Range("C32").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-28]C[42]"
Range("C33").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-29]C[43]"
Range("C34").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-30]C[44]"
Range("C35").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-31]C[45]"
Range("C36").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-32]C[46]"
Range("C37").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-33]C[47]"
Range("C38").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-34]C[48]"
Range("C39").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-35]C[49]"
Range("A40:D40").Select
ActiveWindow.SmallScroll Down:=15
Range("C41").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-37]C[50]"
Range("C42").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-38]C[51]"
Range("C43").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-39]C[52]"
Range("C45").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-41]C[53]"
Range("C47").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-43]C[54]"
Range("C48").Select
ActiveSheet.Name = Range("A13").Value
End Sub
Thanks
You requirement is very much unclear and we don't even know how your 'Summery' sheet looks like (Perhaps a typo there). So I am writing this piece of code to give you an idea of how you can achieve this. Just change the references to the 'summery' sheet according to your requirement or make them dynamic.
Sub do_random()
last_row = ThisWorkbook.Worksheets("Summery").Cells(1, 1).End(xlDown).Row
For i = 1 To last_row
Sheets("Master").Select
Sheets("Master").Copy After:=Sheets(2)
Range("A13").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-9]C[1]"
Range("A15").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-11]C[2]"
Range("E13").Select
ActiveCell.FormulaR1C1 = "=Summery!R[-9]C[-1]"
....
'Do what ever you want in here.
Next i
End Sub

Macro to Run and Loop through all worksheets but the first one

I have the below macro. I am looking for 2 things:
1) A better way to write it (I can't seem to make it work with ranges or any other way)
2) Have it loop through all worksheets (unknown amount, unknown names) except the first one.
Sub Macro1()
'
' Macro1 Macro
'
Range("C3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C"
Range("C4").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-2]C"
Range("C5").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-3]C"
Range("C6").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-4]C"
Range("C7").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-5]C"
Range("C8").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-6]C"
Range("C9").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-7]C"
Range("C10").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-8]C"
Range("C11").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-9]C"
Range("C12").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-10]C"
Range("C13").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-11]C"
Range("C14").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-12]C"
Range("C15").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-13]C"
Range("C16").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-14]C"
Range("C17").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-15]C"
Range("C18").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-16]C"
Range("C19").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-17]C"
Range("C20").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-18]C"
Range("C21").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-19]C"
Range("C22").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-20]C"
Range("C23").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-21]C"
Range("C24").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-22]C"
Range("C25").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-23]C"
Range("C26").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-24]C"
Range("D3").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-1]C"
Range("D4").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-2]C"
Range("D5").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-3]C"
Range("D6").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-4]C"
Range("D7").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-5]C"
Range("D8").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-6]C"
Range("D9").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-7]C"
Range("D10").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-8]C"
Range("D11").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-9]C"
Range("D12").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-10]C"
Range("D13").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-11]C"
Range("D14").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-12]C"
Range("D15").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-13]C"
Range("D16").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-14]C"
Range("D17").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-15]C"
Range("D18").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-16]C"
Range("D19").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-17]C"
Range("D20").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-18]C"
Range("D21").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-19]C"
Range("D22").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-20]C"
Range("D23").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-21]C"
Range("D24").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-22]C"
Range("D25").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-23]C"
Range("D26").Select
ActiveCell.FormulaR1C1 = "=RC[-2]*R[-24]C"
Range("E3").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C"
Range("E4").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-2]C"
Range("E5").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-3]C"
Range("E6").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-4]C"
Range("E7").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-5]C"
Range("E8").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-6]C"
Range("E9").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-7]C"
Range("E10").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-8]C"
Range("E11").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-9]C"
Range("E12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-10]C"
Range("E13").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-11]C"
Range("E14").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-12]C"
Range("E15").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-13]C"
Range("E16").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-14]C"
Range("E17").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-15]C"
Range("E18").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-16]C"
Range("E19").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-17]C"
Range("E20").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-18]C"
Range("E21").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-19]C"
Range("E22").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-20]C"
Range("E23").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-21]C"
Range("E24").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-22]C"
Range("E25").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-23]C"
Range("E26").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-24]C"
Range("F3").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-1]C"
Range("F4").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-2]C"
Range("F5").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-3]C"
Range("F6").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-4]C"
Range("F7").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-5]C"
Range("F8").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-6]C"
Range("F9").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-7]C"
Range("F10").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-8]C"
Range("F11").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-9]C"
Range("F12").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-10]C"
Range("F13").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-11]C"
Range("F14").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-12]C"
Range("F15").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-13]C"
Range("F16").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-14]C"
Range("F17").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-15]C"
Range("F18").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-16]C"
Range("F19").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-17]C"
Range("F20").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-18]C"
Range("F21").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-19]C"
Range("F22").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-20]C"
Range("F23").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-21]C"
Range("F24").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-22]C"
Range("F25").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-23]C"
Range("F26").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*R[-24]C"
Range("G3").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-1]C"
Range("G4").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-2]C"
Range("G5").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-3]C"
Range("G6").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-4]C"
Range("G7").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-5]C"
Range("G8").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-6]C"
Range("G9").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-7]C"
Range("G10").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-8]C"
Range("G11").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-9]C"
Range("G12").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-10]C"
Range("G13").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-11]C"
Range("G14").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-12]C"
Range("G15").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-13]C"
Range("G16").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-14]C"
Range("G17").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-15]C"
Range("G18").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-16]C"
Range("G19").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-17]C"
Range("G20").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-18]C"
Range("G21").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-19]C"
Range("G22").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-20]C"
Range("G23").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-21]C"
Range("G24").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-22]C"
Range("G25").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-23]C"
Range("G26").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*R[-24]C"
Range("H3").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-1]C"
Range("H4").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-2]C"
Range("H5").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-3]C"
Range("H6").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-4]C"
Range("H7").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-5]C"
Range("H8").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-6]C"
Range("H9").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-7]C"
Range("H10").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-8]C"
Range("H11").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-9]C"
Range("H12").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-10]C"
Range("H13").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-11]C"
Range("H14").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-12]C"
Range("H15").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-13]C"
Range("H16").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-14]C"
Range("H17").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-15]C"
Range("H18").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-16]C"
Range("H19").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-17]C"
Range("H20").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-18]C"
Range("H21").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-19]C"
Range("H22").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-20]C"
Range("H23").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-21]C"
Range("H24").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-22]C"
Range("H25").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-23]C"
Range("H26").Select
ActiveCell.FormulaR1C1 = "=RC[-6]*R[-24]C"
Range("I3").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-1]C"
Range("I4").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-2]C"
Range("I5").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-3]C"
Range("I6").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-4]C"
Range("I7").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-5]C"
Range("I8").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-6]C"
Range("I9").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-7]C"
Range("I10").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-8]C"
Range("I11").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-9]C"
Range("I12").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-10]C"
Range("I13").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-11]C"
Range("I14").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-12]C"
Range("I15").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-13]C"
Range("I16").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-14]C"
Range("I17").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-15]C"
Range("I18").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-16]C"
Range("I19").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-17]C"
Range("I20").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-18]C"
Range("I21").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-19]C"
Range("I22").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-20]C"
Range("I23").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-21]C"
Range("I24").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-22]C"
Range("I25").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-23]C"
Range("I26").Select
ActiveCell.FormulaR1C1 = "=RC[-7]*R[-24]C"
Range("J3").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-1]C"
Range("J4").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-2]C"
Range("J5").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-3]C"
Range("J6").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-4]C"
Range("J7").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-5]C"
Range("J8").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-6]C"
Range("J9").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-7]C"
Range("J10").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-8]C"
Range("J11").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-9]C"
Range("J12").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-10]C"
Range("J13").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-11]C"
Range("J14").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-12]C"
Range("J15").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-13]C"
Range("J16").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-14]C"
Range("J17").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-15]C"
Range("J18").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-16]C"
Range("J19").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-17]C"
Range("J20").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-18]C"
Range("J21").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-19]C"
Range("J22").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-20]C"
Range("J23").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-21]C"
Range("J24").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-22]C"
Range("J25").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-23]C"
Range("J26").Select
ActiveCell.FormulaR1C1 = "=RC[-8]*R[-24]C"
Range("K3").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-1]C"
Range("K4").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-2]C"
Range("K5").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-3]C"
Range("K6").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-4]C"
Range("K7").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-5]C"
Range("K8").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-6]C"
Range("K9").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-7]C"
Range("K10").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-8]C"
Range("K11").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-9]C"
Range("K12").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-10]C"
Range("K13").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-11]C"
Range("K14").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-12]C"
Range("K15").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-13]C"
Range("K16").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-14]C"
Range("K17").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-15]C"
Range("K18").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-16]C"
Range("K19").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-17]C"
Range("K20").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-18]C"
Range("K21").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-19]C"
Range("K22").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-20]C"
Range("K23").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-21]C"
Range("K24").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-22]C"
Range("K25").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-23]C"
Range("K26").Select
ActiveCell.FormulaR1C1 = "=RC[-9]*R[-24]C"
Range("L3").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-1]C"
Range("L4").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-2]C"
Range("L5").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-3]C"
Range("L6").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-4]C"
Range("L7").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-5]C"
Range("L8").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-6]C"
Range("L9").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-7]C"
Range("L10").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-8]C"
Range("L11").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-9]C"
Range("L12").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-10]C"
Range("L13").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-11]C"
Range("L14").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-12]C"
Range("L15").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-13]C"
Range("L16").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-14]C"
Range("L17").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-15]C"
Range("L18").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-16]C"
Range("L19").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-17]C"
Range("L20").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-18]C"
Range("L21").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-19]C"
Range("L22").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-20]C"
Range("L23").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-21]C"
Range("L24").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-22]C"
Range("L25").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-23]C"
Range("L26").Select
ActiveCell.FormulaR1C1 = "=RC[-10]*R[-24]C"
Range("M3").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-1]C"
Range("M4").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-2]C"
Range("M5").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-3]C"
Range("M6").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-4]C"
Range("M7").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-5]C"
Range("M8").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-6]C"
Range("M9").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-7]C"
Range("M10").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-8]C"
Range("M11").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-9]C"
Range("M12").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-10]C"
Range("M13").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-11]C"
Range("M14").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-12]C"
Range("M15").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-13]C"
Range("M16").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-14]C"
Range("M17").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-15]C"
Range("M18").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-16]C"
Range("M19").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-17]C"
Range("M20").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-18]C"
Range("M21").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-19]C"
Range("M22").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-20]C"
Range("M23").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-21]C"
Range("M24").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-22]C"
Range("M25").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-23]C"
Range("M26").Select
ActiveCell.FormulaR1C1 = "=RC[-11]*R[-24]C"
Range("N3").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-1]C"
Range("N4").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-2]C"
Range("N5").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-3]C"
Range("N6").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-4]C"
Range("N7").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-5]C"
Range("N8").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-6]C"
Range("N9").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-7]C"
Range("N10").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-8]C"
Range("N11").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-9]C"
Range("N12").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-10]C"
Range("N13").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-11]C"
Range("N14").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-12]C"
Range("N15").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-13]C"
Range("N16").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-14]C"
Range("N17").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-15]C"
Range("N18").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-16]C"
Range("N19").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-17]C"
Range("N20").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-18]C"
Range("N21").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-19]C"
Range("N22").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-20]C"
Range("N23").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-21]C"
Range("N24").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-22]C"
Range("N25").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-23]C"
Range("N26").Select
ActiveCell.FormulaR1C1 = "=RC[-12]*R[-24]C"
Range("O3").Select
ActiveCell.FormulaR1C1 = _
"=RC[-12]+RC[-11]+RC[-10]+RC[-9]+RC[-8]+RC[-7]+RC[-6]+RC[-5]+RC[-4]+RC[-3]+RC[-2]+RC[-1]"
Range("O3").Select
Selection.AutoFill Destination:=Range("O3:O26"), Type:=xlFillDefault
Range("O3:O26").Select
End Sub
edited after OP's comment
try this:
Option Explicit
Sub Macro1()
Dim i As Long
For i = 2 To Worksheets.count
With Worksheets(i).Range("C3:O26")
.Resize(, Columns.count - 1).FormulaR1C1 = "=RC2*R2C"
.Columns(.Columns.count).Resize(, 1).FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
.NumberFormat = "$#,##0.00"
End With
Next
End Sub

Macro to Auto Fill Down to last adjacent cells

I want my macro to populate my formulas all the way down the sheet. Every time I run the macro it stops at row 13662 because that was the last row when I was recording it, but the last row changes constantly. Is there a way to do this?
The columns I need to do this for are N, I, J, K, and L. Any help appreciated. See code below.
Sub Weekly_Expiring_Rebate_Report()
'
' Weekly_Expiring_Rebate_Report Macro
'
'
Columns("A:A").Select
Range(Selection, Selection.End(xlToRight)).Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("A:A").Select
Range(Selection, Selection.End(xlToRight)).Select
Columns("A:Z").EntireColumn.AutoFit
Columns("N:N").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.NumberFormat = "General"
Range("N1").Select
ActiveCell.FormulaR1C1 = "Expiring Rebate Status"
Range("N2").Select
Columns("N:N").EntireColumn.AutoFit
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'Status IND'!C[-13]:C[-11],3,FALSE)"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N13662")
Range("N2:N13662").Select
Columns("I:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("I2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],4)"
Range("I2").Select
Selection.AutoFill Destination:=Range("I2:I13662")
Range("I2:I13662").Select
Range("J2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-2],6)"
Range("J2").Select
Selection.AutoFill Destination:=Range("J2:J13662")
Range("J2:J13662").Select
Range("K2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],2)"
Range("K2").Select
Selection.AutoFill Destination:=Range("K2:K13662")
Range("K2:K13662").Select
Range("L2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-4],2)"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L13662")
Range("L2:L13662").Select
Range("I1").Select
ActiveCell.FormulaR1C1 = "EXP_YEAR"
Range("K1").Select
ActiveCell.FormulaR1C1 = "EXP_MONTH"
Range("L1").Select
ActiveCell.FormulaR1C1 = "EXP_DAY"
Columns("I:L").Select
Range("L1").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("J:J").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("L1").Select
ActiveCell.FormulaR1C1 = "EXP_Month_Name"
Columns("I:L").Select
Range("L1").Activate
Columns("I:L").EntireColumn.AutoFit
Range("L2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2],Month!C[-11]:C[-10],2,FALSE)"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L13662")
Range("L2:L13662").Select
ActiveWindow.SmallScroll Down:=-6
Columns("M:M").Select
End Sub
It looks like your issue is on the 5th row from the end.
Based on this answer you could replace:
Selection.AutoFill Destination:=Range("L2:L13662")
with
Selection.AutoFill Destination:=Range("L2:L" & ActiveSheet.UsedRange.Rows.Count)
Here is an example of vba code that I think will work for your purposes.
'Counts the number of rows in column "C" and then places
'concatenation formula in each adjacent cell (in column "D").
Range("D2:D" & Range("C" & Rows.Count).End(xlUp).Row).Formula = "=CONCATENATE(C2,"", "",B2)"

Excel Macro generating single random output

I recorded a macro that runs through a bunch of formatting and splicing of data. It basically formats the data page, then splices it into months. The data roughly looks like this:
Column A ... Column D ... Column H Column I Jan Feb ... Nov Dec
- 00645 - budget 45.2 32.8 -15.0 100.00
Basically it fills in entries for all of column A (all entries are "LINE"), renames header on columns B, C, D, H, and I, then copys columns A-J and moves it to a tab created just for the specific month, then deletes column J so the next month will always be in column J and continues repeating till all months are parsed out. Its a pretty easy macro, mostly recorded, but its behaving strangely.
The issue is that once it runs, it randomly inputs the value that is only supposed to be in column A ("LINE") to a single cell somewhere else in the file. It seems semi-random which cell it is. If you put in data from File A, no matter how many times you run the macro "LINE" will show up in the same cell. But it will be a different cell for Files B, C, D and so on. There is nothing fundamentially different about the cell it does this in when compared to the other cells (same entry, same formatting, etc). I have no idea why its doing this. Below is my code:
Sub Format_Upload()
Format_Upload Macro
ActiveCell.FormulaR1C1 = "LINE"
LastRow = Range("B" & Rows.Count).End(xlUp).Row
Range("A2").Copy Range("A2").Resize(LastRow - 1)
Range("B1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Dept ID"
Range("C1").Select
ActiveCell.FormulaR1C1 = "MSUPLOAD1"
Range("D1").Select
ActiveCell.FormulaR1C1 = "01/01/14"
Range("I1").Select
ActiveCell.FormulaR1C1 = "01/01/14"
Range("D1").Select
Selection.NumberFormat = "mm/dd/yy;#"
Range("I1").Select
Selection.NumberFormat = "mm/dd/yy;#"
Cells.Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("J:U").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Selection.NumberFormat = "0.00"
Columns("A:J").Select
Selection.Copy
Sheets("JAN").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Data").Select
Columns("J:J").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("FEB").Select
Range("A1").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "2/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "2/1/2014"
Range("H1").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("MAR").Select
Range("A1").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "3/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "3/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("APR").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "4/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "4/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Range("J1").Activate
Selection.Copy
Sheets("MAY").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "5/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "5/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("JUN").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "6/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "6/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("JUL").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "7/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "7/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("AUG").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "8/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "8/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("SEP").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "9/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "9/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Selection.Copy
Sheets("OCT").Select
Sheets("Data").Select
Columns("A:J").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("OCT").Select
Range("A1").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "10/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "10/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("NOV").Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "11/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "11/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Selection.Copy
Sheets("DEC").Select
ActiveSheet.Paste
Columns("D:D").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "12/1/2014"
Range("I1").Select
ActiveCell.FormulaR1C1 = "12/1/2014"
Range("I2").Select
Sheets("Data").Select
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Sheets("FEB").Select
ActiveCell.FormulaR1C1 = "MSFEB"
Sheets("MAR").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSMAR"
Sheets("APR").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSAPR"
Sheets("MAY").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSMAY"
Sheets("JUN").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSJUN"
Sheets("JUL").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSJUL"
Sheets("AUG").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSAUG"
Sheets("SEP").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSSEP"
Sheets("OCT").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSOCT"
Sheets("NOV").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSNOV"
Sheets("DEC").Select
Range("H1").Select
ActiveCell.FormulaR1C1 = "MSDEC"
Range("H2").Select
End Sub
I do not see anything in the code that explains this anomaly. Any ideas as to what's causing this issue?
'
EDIT: The strange cell always appears on the first tab (named "JAN"), but its location varies.
ActiveCell.FormulaR1C1 = "LINE"
This is putting "LINE" in whichever cell you have selected before running it.
Change that to something else

run-time error 1004 Could not run the paste method of worksheet class

Hello I have a problem in a macro I made. it was working perfectly, until he started giving this error. and then when I go into debug. shows the error in the following field:
I will post all the code here.
Sub Terca()
'
' Terca Macro
'
' Atalho do teclado: Ctrl+q
'
Range("I55").Select
ActiveWindow.SmallScroll Down:=-33
Range("E17").Select
Selection.ClearContents
Range("E18").Select
Selection.ClearContents
Range("F17").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-6]C[-2]:R[10]C[-2],Dados!R[-12]C[-2])"
Range("E17").Select
ActiveSheet.Paste !!!! <-- ERROR ---> !!!!
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-7]C[-1],Dados!R[-12]C[-1])"
Range("F18").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-7]C[-1]:R[9]C[-1],Dados!R[-13]C[-1])"
Range("E18").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-8]C,Dados!R[-13]C)"
Range("F17").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-7]C[-2]:R[10]C[-2],Dados!R[-12]C[-2])"
Range("F18").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-8]C[-1]:R[9]C[-1],Dados!R[-13]C[-1])"
Range("E21").Select
Selection.ClearContents
Range("E22").Select
Selection.ClearContents
Range("F21").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-10]C[4]:R[6]C[4],Dados!R[-16]C[4])"
Range("E21").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-11]C[5],Dados!R[-16]C[5])"
Range("F22").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-11]C[1]:R[5]C[1],Dados!R[-17]C[1])"
Range("E22").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-12]C[2],Dados!R[-17]C[2])"
Range("F21").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-11]C[4]:R[6]C[4],Dados!R[-16]C[4])"
Range("F22").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-12]C[1]:R[5]C[1],Dados!R[-17]C[1])"
Range("F23").Select
ActiveWindow.SmallScroll Down:=12
Range("E25:E26").Select
Selection.ClearContents
Range("F25").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(Dados!R[-14]C[7]:R[2]C[7],Dados!R[-20]C[7])"
Range("E25").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=AVERAGE(Dados!R[-15]C[8],Dados!R[-20]C[8])"
Range("F26").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(Dados!R[-15]C[8]:R[1]C[8],Dados!R[-21]C[8])"
Range("E26").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=AVERAGE(Dados!R[-16]C[9],Dados!R[-21]C[9])"
Range("F25").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(Dados!R[-15]C[7]:R[2]C[7],Dados!R[-20]C[7])"
Range("F26").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(Dados!R[-16]C[8]:R[1]C[8],Dados!R[-21]C[8])"
Range("F31").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-20]C[11]:R[-4]C[11],Dados!R[-26]C[11])"
Range("E31").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-21]C[12],Dados!R[-26]C[12])"
Range("F32").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-21]C[12]:R[-5]C[12],Dados!R[-27]C[12])"
Range("E32").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-22]C[13],Dados!R[-27]C[13])"
Range("F32").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-22]C[12]:R[-5]C[12],Dados!R[-27]C[12])"
Range("F31").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-21]C[11]:R[-4]C[11],Dados!R[-26]C[11])"
Range("F32").Select
ActiveWindow.SmallScroll Down:=12
Range("F35").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-24]C[13]:R[-8]C[13],Dados!R[-30]C[13])"
Range("E35").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-25]C[14],Dados!R[-30]C[14])"
Range("F36").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-25]C[14]:R[-9]C[14],Dados!R[-31]C[14])"
Range("E36").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-26]C[15],Dados!R[-31]C[15])"
Range("F35").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-25]C[13]:R[-8]C[13],Dados!R[-30]C[13])"
Range("F36").Select
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-26]C[14]:R[-9]C[14],Dados!R[-31]C[14])"
Range("F37").Select
ActiveWindow.SmallScroll Down:=6
Range("E42:E43").Select
Selection.ClearContents
Range("F42").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-31]C[17]:R[-15]C[17],Dados!R[-37]C[17])"
Range("E42").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-32]C[18],Dados!R[-37]C[18])"
Range("F43").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-32]C[18]:R[-16]C[18],Dados!R[-38]C[18])"
Range("E43").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-33]C[19],Dados!R[-38]C[19])"
Range("F43").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-33]C[18]:R[-16]C[18],Dados!R[-38]C[18])"
Range("F42").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-32]C[17]:R[-15]C[17],Dados!R[-37]C[17])"
Range("E46:E47").Select
Selection.ClearContents
Range("F46").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-35]C[21]:R[-19]C[21],Dados!R[-41]C[21])"
Range("E46").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-36]C[22],Dados!R[-41]C[22])"
Range("F47").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-36]C[22]:R[-20]C[22],Dados!R[-42]C[22])"
Range("E47").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-37]C[23],Dados!R[-42]C[23])"
Range("F46").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-36]C[21]:R[-19]C[21],Dados!R[-41]C[21])"
Range("F47").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-37]C[22]:R[-20]C[22],Dados!R[-42]C[22])"
Range("L42").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-31]C[13]:R[-15]C[13],Dados!R[-37]C[13])"
Range("K42").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-32]C[14],Dados!R[-37]C[14])"
Range("L43").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-32]C[14]:R[-16]C[14],Dados!R[-38]C[14])"
Range("K43").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-33]C[15],Dados!R[-38]C[15])"
Range("L46").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-35]C[17]:R[-19]C[17],Dados!R[-41]C[17])"
Range("K46").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-35]C[17]:R[-19]C[17],Dados!R[-41]C[17])"
Range("K46").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-36]C[18],Dados!R[-41]C[18])"
Range("L47").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-36]C[18]:R[-20]C[18],Dados!R[-42]C[18])"
Range("K47").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "=SUM(Dados!R[-37]C[19],Dados!R[-42]C[19])"
Range("L47").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-37]C[18]:R[-20]C[18],Dados!R[-42]C[18])"
Range("L46").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-36]C[17]:R[-19]C[17],Dados!R[-41]C[17])"
Range("L43").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-33]C[14]:R[-16]C[14],Dados!R[-38]C[14])"
Range("L42").Select
ActiveCell.FormulaR1C1 = _
"=SUM(Dados!R[-32]C[13]:R[-15]C[13],Dados!R[-37]C[13])"
Range("P48").Select
ActiveWindow.SmallScroll Down:=-9
End Sub
may I suggest the below improvements to your (recorded?) code:
Sub Terca()
'
' Terca Macro
'
' Atalho do teclado: Ctrl+q
'
Range("E17:E18,E21:E22,E25:E26,E46:E47,E42:E43").ClearContents
Range("F17").FormulaR1C1 = "=SUM(Dados!R[-6]C[-2]:R[10]C[-2],Dados!R[-12]C[-2])"
Range("E17").FormulaR1C1 = "=SUM(Dados!R[-7]C[-1],Dados!R[-12]C[-1])"
Range("F18").FormulaR1C1 = "=SUM(Dados!R[-7]C[-1]:R[9]C[-1],Dados!R[-13]C[-1])"
Range("E18").FormulaR1C1 = "=SUM(Dados!R[-8]C,Dados!R[-13]C)"
Range("F17").FormulaR1C1 = "=SUM(Dados!R[-7]C[-2]:R[10]C[-2],Dados!R[-12]C[-2])"
Range("F18").FormulaR1C1 = "=SUM(Dados!R[-8]C[-1]:R[9]C[-1],Dados!R[-13]C[-1])"
Range("E21").FormulaR1C1 = "=SUM(Dados!R[-10]C[4]:R[6]C[4],Dados!R[-16]C[4])"
Range("E21").FormulaR1C1 = "=SUM(Dados!R[-11]C[5],Dados!R[-16]C[5])"
Range("F22").FormulaR1C1 = "=SUM(Dados!R[-11]C[1]:R[5]C[1],Dados!R[-17]C[1])"
Range("E22").FormulaR1C1 = "=SUM(Dados!R[-12]C[2],Dados!R[-17]C[2])"
Range("F21").FormulaR1C1 = "=SUM(Dados!R[-11]C[4]:R[6]C[4],Dados!R[-16]C[4])"
Range("F22").FormulaR1C1 = "=SUM(Dados!R[-12]C[1]:R[5]C[1],Dados!R[-17]C[1])"
Range("F25").FormulaR1C1 = "=AVERAGE(Dados!R[-14]C[7]:R[2]C[7],Dados!R[-20]C[7])"
Range("E25").FormulaR1C1 = "=AVERAGE(Dados!R[-15]C[8],Dados!R[-20]C[8])"
Range("F26").FormulaR1C1 = "=AVERAGE(Dados!R[-15]C[8]:R[1]C[8],Dados!R[-21]C[8])"
Range("E26").FormulaR1C1 = "=AVERAGE(Dados!R[-16]C[9],Dados!R[-21]C[9])"
Range("F25").FormulaR1C1 = "=AVERAGE(Dados!R[-15]C[7]:R[2]C[7],Dados!R[-20]C[7])"
Range("F26").FormulaR1C1 = "=AVERAGE(Dados!R[-16]C[8]:R[1]C[8],Dados!R[-21]C[8])"
Range("F31").FormulaR1C1 = "=SUM(Dados!R[-20]C[11]:R[-4]C[11],Dados!R[-26]C[11])"
Range("E31").FormulaR1C1 = "=SUM(Dados!R[-21]C[12],Dados!R[-26]C[12])"
Range("F32").FormulaR1C1 = "=SUM(Dados!R[-21]C[12]:R[-5]C[12],Dados!R[-27]C[12])"
Range("E32").FormulaR1C1 = "=SUM(Dados!R[-22]C[13],Dados!R[-27]C[13])"
Range("F32").FormulaR1C1 = "=SUM(Dados!R[-22]C[12]:R[-5]C[12],Dados!R[-27]C[12])"
Range("F31").FormulaR1C1 = "=SUM(Dados!R[-21]C[11]:R[-4]C[11],Dados!R[-26]C[11])"
Range("F35").FormulaR1C1 = "=SUM(Dados!R[-24]C[13]:R[-8]C[13],Dados!R[-30]C[13])"
Range("E35").FormulaR1C1 = "=SUM(Dados!R[-25]C[14],Dados!R[-30]C[14])"
Range("F36").FormulaR1C1 = "=SUM(Dados!R[-25]C[14]:R[-9]C[14],Dados!R[-31]C[14])"
Range("E36").FormulaR1C1 = "=SUM(Dados!R[-26]C[15],Dados!R[-31]C[15])"
Range("F35").FormulaR1C1 = "=SUM(Dados!R[-25]C[13]:R[-8]C[13],Dados!R[-30]C[13])"
Range("F36").FormulaR1C1 = "=SUM(Dados!R[-26]C[14]:R[-9]C[14],Dados!R[-31]C[14])"
Range("F42").FormulaR1C1 = "=SUM(Dados!R[-31]C[17]:R[-15]C[17],Dados!R[-37]C[17])"
Range("E42").FormulaR1C1 = "=SUM(Dados!R[-32]C[18],Dados!R[-37]C[18])"
Range("F43").FormulaR1C1 = "=SUM(Dados!R[-32]C[18]:R[-16]C[18],Dados!R[-38]C[18])"
Range("E43").FormulaR1C1 = "=SUM(Dados!R[-33]C[19],Dados!R[-38]C[19])"
Range("F43").FormulaR1C1 = "=SUM(Dados!R[-33]C[18]:R[-16]C[18],Dados!R[-38]C[18])"
Range("F42").FormulaR1C1 = "=SUM(Dados!R[-32]C[17]:R[-15]C[17],Dados!R[-37]C[17])"
Range("F46").FormulaR1C1 = "=SUM(Dados!R[-35]C[21]:R[-19]C[21],Dados!R[-41]C[21])"
Range("E46").FormulaR1C1 = "=SUM(Dados!R[-36]C[22],Dados!R[-41]C[22])"
Range("F47").FormulaR1C1 = "=SUM(Dados!R[-36]C[22]:R[-20]C[22],Dados!R[-42]C[22])"
Range("E47").FormulaR1C1 = "=SUM(Dados!R[-37]C[23],Dados!R[-42]C[23])"
Range("F46").FormulaR1C1 = "=SUM(Dados!R[-36]C[21]:R[-19]C[21],Dados!R[-41]C[21])"
Range("F47").FormulaR1C1 = "=SUM(Dados!R[-37]C[22]:R[-20]C[22],Dados!R[-42]C[22])"
Range("L42").FormulaR1C1 = "=SUM(Dados!R[-31]C[13]:R[-15]C[13],Dados!R[-37]C[13])"
Range("K42").FormulaR1C1 = "=SUM(Dados!R[-32]C[14],Dados!R[-37]C[14])"
Range("L43").FormulaR1C1 = "=SUM(Dados!R[-32]C[14]:R[-16]C[14],Dados!R[-38]C[14])"
Range("K43").FormulaR1C1 = "=SUM(Dados!R[-33]C[15],Dados!R[-38]C[15])"
Range("L46").FormulaR1C1 = "=SUM(Dados!R[-35]C[17]:R[-19]C[17],Dados!R[-41]C[17])"
Range("K46").FormulaR1C1 = "=SUM(Dados!R[-35]C[17]:R[-19]C[17],Dados!R[-41]C[17])"
Range("K46").FormulaR1C1 = "=SUM(Dados!R[-36]C[18],Dados!R[-41]C[18])"
Range("L47").FormulaR1C1 = "=SUM(Dados!R[-36]C[18]:R[-20]C[18],Dados!R[-42]C[18])"
Range("K47").FormulaR1C1 = "=SUM(Dados!R[-37]C[19],Dados!R[-42]C[19])"
Range("L47").FormulaR1C1 = "=SUM(Dados!R[-37]C[18]:R[-20]C[18],Dados!R[-42]C[18])"
Range("L46").FormulaR1C1 = "=SUM(Dados!R[-36]C[17]:R[-19]C[17],Dados!R[-41]C[17])"
Range("L43").FormulaR1C1 = "=SUM(Dados!R[-33]C[14]:R[-16]C[14],Dados!R[-38]C[14])"
Range("L42").FormulaR1C1 = "=SUM(Dados!R[-32]C[13]:R[-15]C[13],Dados!R[-37]C[13])"
End Sub
no need to select cells before assigning a value.
don't try to paste if there is nothing in the clipboard suitable for pasting
HTH
Philip