Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe?
Sub Auto_Fill() Dim Lrow As Long With ActiveSheet Lrow = .Range("AG" & Rows.Count).End(xlUp).Row .Range("AG4:AM" & Lrow).FillDown End With End Sub Gord Dibben MS Excel MVP On Tue, 23 Dec 2008 09:30:04 -0800, Kell2604 wrote: Guys...I'm still getting an error. This formula works great if I'm just trying to autofil 1 column. I seem to be having trouble with autofilling 5 consecutive columns. I could do it one by one with my original code but that seems like a lot of unnecessary work. This is what I have currently...with the updates suggested. lRow = Cells(Rows.Count, "AG").End(xlUp).Row Range("AG4").AutoFill Destination:=Range("AG4:AM" & lRow) New error - AutoFill method of Range class failed. "JE McGimpsey" wrote: For one thing, 65000 is not the last row in a worksheet, even prior to XL07, so if there were 65535 rows of data, your method would fail while the first method would work. Obviously, XL07/08 files have LOTS more than 65000 rows. The first method will work on either file type. Second, using the evaluate method as you're doing *can* be slightly more inefficient than using Cells(). Won't make a jot of difference when run once, but most people feel it's better coding practice. Third, it's a lot easier to generalize the Cells() method. Instead of a constant, the "AG4" part could be calculated, or specified in a constant, making it much easier to change one calculation (or constant) and have all Cells() methods adjust, rather than having to search the project for each instance of "AG". In article , Greg Snidow wrote: Don, what is the difference between finding the last row as you are doing here, lRow = cells(rows.count,"AG4").End(xlUP).Row, and as I usually do, like this: LstRow = [F65000].End(xlUp).Row? I see this method all the time, so it is what I use in all my macros. Are there situations where your method would be better? And if so, why? Just trying to understand. Thank you. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need to autofil a formula that is not recognised? | Excel Discussion (Misc queries) | |||
simple question on formulas and autofil | Excel Worksheet Functions | |||
Autofil from a list box (data validation) | Excel Programming | |||
Autofil a cell in the same row. | Excel Worksheet Functions | |||
Excel VBA question - Running a autofil | Excel Programming |