|
Question : Macro to carry formulas down a sheet
|
|
I realize that this is probably not enough information at this time but it would take a great deal to present all the necessary information to actually write the macro. i would like to first find out if it is possible so i will give an explanation and if possible we can get much more detailed. I have a spread sheet where on line nine there is a row of formulas that refer tto other sheets and also to each other. on the sheet that contains the formulas and space to input information I highlight the entire row (it is row nine) and then drag it down however far I need to for the project ai am estimating. row A & row B have formulas in them. rows C through are void of formulas and that is where I enter information. Rows AR through HV also have fromulas in them the formulas only use information that is on that particular line and alos information it "looks up on other sheets. Rather then dragging the formulas on line 9 all the way down the sheet and making the sheet very large I would like a macro that would aoutomatically do this when information is entered in the cells iin that particular row. i hope i have explained this sufficently. A typical spread sheet is about 34,000,000 K and if this could be accomplished it would cut this number in half on larger estimates. Is this possible?
thanks, Bill
|
|
Answer : Macro to carry formulas down a sheet
|
|
Bill, If you still have data in the last rows of the worksheet, I can understand the error message. But if you cleared those rows before running the new macro, it shouldn't have occurred.
I also got errors when the used range on the worksheet didn't extend past the cells being selected. Here is a workaround for that possibility. I've tested it in both Excel 97 and 2003.
Sub CopyDown() 'Copies formulas and formatting down to the bottom of the worksheet Dim ar As Range, rg As Range, rgFill As Range Dim nLastRow As Long Application.ScreenUpdating = False Set rg = Selection nLastRow = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Rows.Count - 1 For Each ar In rg.Areas Set rgFill = ar.Resize(nLastRow - ar.Row + 1) If rgFill.Rows.Count > ar.Rows.Count Then ar.AutoFill rgFill, xlFillDefault 'rgFill.Formula = rgFill.Value 'Gets rid of all formulas 'Gets rid of just those formulas that were copied down rgFill.Offset(ar.Rows.Count, 0).Resize(rgFill.Rows.Count - ar.Rows.Count).Formula = _ rgFill.Offset(ar.Rows.Count, 0).Resize(rgFill.Rows.Count - ar.Rows.Count).Value End If Next Application.ScreenUpdating = True End Sub
Brad
|
|
|
|