See line 515 and 516 - they both accomplish the same thing.
When users grab the lower right handle of a cell containing a formula and drag it across several cells, they are implementing a Autofill.
This example shows two ways to accomplish the same thing.
Sometimes, the cell method is useful in a loop with variables.
30 Set objXL = CreateObject("Excel.Application")
50 With objXL
400 .Worksheets(2).Range("A1").Select
410 .Cells.Select
420 .Cells.EntireColumn.AutoFit
430 .Worksheets(2).Range("A1").Select
440 .Worksheets(2).Range("A1:H1").Select 'header row bolded
450 .Selection.Font.Bold = True
460 .ActiveWindow.SplitRow = 1 ' add split row autofilter - then insert totals above afterwards
470 .ActiveWindow.FreezePanes = True
480 .Rows("1:1").Select
490 .Selection.Insert Shift:=xlDown
500 .Worksheets(2).Cells(1, 3).Select
510 .ActiveCell.FormulaR1C1 = "=SUBTOTAL(109,R[2]C:R[49999]C)" ' total all that are visable
511 .Worksheets(2).Cells(1, 3).Select
512 DoEvents ' runs fine in stepthrough mode - sometimes fails in runtime for older PC
513 objXL.Worksheets(2).Range("C1").Select
515 '.Selection.AutoFill Destination:=Range("C1:H1") ' Note: the next line accomplishes the same thing
516 objXL.Worksheets(2).Range("C1").AutoFill Destination:=Range(Cells(1, 3), Cells(1, 8)) ' Alternate method
1000 End With
Bookmarks