LactoseO.D.'d
Board Regular
- Joined
- Feb 22, 2010
- Messages
- 52
I am trying to use autofill to populate the results of a formula on to a table.
I have no problems autofilling one column, which is where I'm at now:
(ignore the value errors, I will fix those later)
But I need to go across all the columns, similar to how I would if I just grabbed the box on the lower right of this selection across.
Of course the table size is undefined, so I have a suspicion I need to write some sort of loop that will repeat the column fill until I am out of columns with data.
Spreadsheet:
http://www.box.net/files#/files/0/f/0/1/f_871677463
Code so far:
I've spent the day looking for sample code to do this -no dice.
I have no problems autofilling one column, which is where I'm at now:
(ignore the value errors, I will fix those later)
But I need to go across all the columns, similar to how I would if I just grabbed the box on the lower right of this selection across.
Of course the table size is undefined, so I have a suspicion I need to write some sort of loop that will repeat the column fill until I am out of columns with data.
Spreadsheet:
http://www.box.net/files#/files/0/f/0/1/f_871677463
Code so far:
Code:
Sub Macro2()
Dim RSQ As Range
' Macro2 Macro
'
'Create R2 Sheet
Sheets.Add
ActiveWindow.ActiveSheet.Name = "R2"
Sheets("Dataset").Select
Range("A1").Select
ActiveCell.CurrentRegion.Select
Selection.Copy
Sheets("R2").Select
ActiveSheet.Paste
Range("C3").Select
Range("A1").Value = "R2 Table"
Rows("1:1").Hidden = True
Columns("A:A").Hidden = True
'Define datset
Sheets("Dataset").Select
Range("C3").Select
Sheets("R2").Select
Range("C3").Select
Sheets("Dataset").Select
Range("C3").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.Names.Add Name:="DATA", RefersTo:=Selection
'Populate R2 Data
Sheets("R2").Select
Range("C3").Select
ActiveCell.FormulaR1C1 = _
"=INDEX(LINEST(INDEX(data,0,RC2),INDEX(data,0,R2C),,TRUE),3,1)"
Range("c3").AutoFill Destination:=Range("c3:c" & Range("d3").End(xlDown).Row)
End Sub
I've spent the day looking for sample code to do this -no dice.