I'm trying to clean up my recorded Macro to make it less prone to error when I run it in future months (I'm trying to automate my monthly reporting). I have heard references to Activecell and the like can be dangerous so I'm looking to sure it up.
Outline of requirement. I'm using multiple formulas to grab contents from another worksheet and fill down to the end of said data on the other worksheet.
Sub AnswesComboFill()
Range("A2").Select
ActiveCell.FormulaR1C1 = "=EvalTableData!RC[2]"
Range("B2").Select
ActiveCell.FormulaR1C1 = "=EvalTableData!RC[4]"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=EvalTableData!RC[1]"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(EvalTableData!RC[-3],AnswersData!C[-3]:C[2],6)"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(EvalTableData!RC[-4],AnswersData!C[2]:C[7],6)"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(EvalTableData!RC[-5],AnswersData!C[7]:C[12],6)"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(EvalTableData!RC[-6],AnswersData!C[12]:C[17],6)"
Range("H2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(EvalTableData!RC[-7],AnswersData!C[17]:C[22],6)"
Range("A2:H2").Select
Selection.AutoFill Destination:=Range("A2:H2000"), Type:=xlFillDefault
Range("A2:H2000").Select
Selection.NumberFormat = "General"
End Sub
Questions:
Can I get some direction for changing it so the cell references are static?
Some of the cells I'm referring to are formatted as Text, hence the last line to format to General. Even though I change the format to general the contents still stay as text (for example A2 will just say "=EvalTableData!A2" and not the contents). Is there a way to refresh the contents after I've changed the format?
I would like to the fill down range to be dynamic and not A2:H2000 like in the formula. I currently have a range.lastcell style formula in one of my other macros but it doesn't work in this case because I'm referring to a different worksheet. Can I get some assistance with that too?