VBA: Copy A Formula into a Cell - then AutoFill a Range with the Formula / Values - Scenario is as follows:
Here is what I have - it is bombing at ActiveSheet.Paste (pulled from recording the macro)
Thanks in advance
- Data in Sheet1 goes from ("B3: to Unknown Last Column & row 13")
- Find Last column in Sheet1 with data - put into LastCol
- RANK Sheet1 data IN Sheet2 (putting in same spot... what was in Sheet1 B3 Rank goes in Sheet2 B3 spot).
- Copy and Auto fill into a range, this formula (assuming it is correct syntax),=RANK(Sheet1!B3,Sheet1!$B3:$" & LastCol & "3)
- Autofill Range ("B3: to Unknown Last Column & row 13") on Sheet2
- If I can get this working... ideally, I would want the VALUES and not formulas left in Sheet2
Here is what I have - it is bombing at ActiveSheet.Paste (pulled from recording the macro)
Code:
Public wb As Workbook
Code:
[INDENT]Public wsSummary As Worksheet[/INDENT]
[INDENT]Sub AutoFill_RANKForm()[/INDENT]
[INDENT]
[/INDENT]
[INDENT]Set wsSummary = wb.Sheets.Add(After:=wb.Sheets(Worksheets.Count))[/INDENT]
[INDENT] wsSummary.Name = "Sheet2"[/INDENT]
[INDENT]
[/INDENT]
[INDENT]LastCol = Split(Columns(Range("A1").End(xlToRight).Column).Address(, False), ":")(1)[/INDENT]
[INDENT]
[/INDENT]
[INDENT] ActiveCell.FormulaR1C1 = "=RANK(Sheet1!B3,Sheet1!$B3:$" & LastCol & "3)"[/INDENT]
[INDENT] Range("B3").Select[/INDENT]
[INDENT] ActiveSheet.Paste[/INDENT]
[INDENT] Selection.AutoFill Destination:=Range("B3:" & LastCol & "13"), Type:=xlFillDefault[/INDENT]
[INDENT] Range("B3" & LastCol & "13").Select[/INDENT]
[INDENT]
[/INDENT]
[INDENT]End Sub[/INDENT]