View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default run-time error 1004 (How to FIll Down a Formula in a List)

Hi Kelli,

No, you are not missing anything on the line where "LastRow =
ActiveSheet.UsedRange.Rows.Count".

Use the code as given. Here is the complete routine, as I tested it.
LastRow is a Long data type (a long form of integer). It is not an object
variable, so it does not need to be "Set". If you step through the code
(use the <F8 key) and watch the Locals window, you will see LastRow take
on the value of how many rows you currently have on your worksheet. The
next line of code will then fill in the formula in column $O from row 1
down to the last row. I removed the comments I had to prevent them from
causing line wrap problems when you cut and paste the code from the
newsgroup into a code window in Excel.

Public Sub FillColumnO()
Dim LastRow As Long

LastRow = ActiveSheet.UsedRange.Rows.Count
Range("O1:O" & LastRow).Formula = "=A1+B1/C1"
End Sub

If you had an object variable, then you would use "Set" as in the following
example. Try this routine also, just to see how an object variable works.

Public Sub GetList()
Dim rngList As Range

Set rngList = ActiveSheet.UsedRange

rngList.Select
End Sub

--
Regards,
Bill Renaud