View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default How to use a variable as an argument in .FliiDown

The problem with your code is enclosing the y in double quotes. Instead of
recognizing it as the variable to which the range is assigned, it becomes the
string y. Just removing the double quotes and it works.

Dim myLastFilledFormulaRow
Dim y As Range

myLastFilledFormulaRow = 10 'For testing only

Range("F" & myLastFilledFormulaRow).Select
Set y = Selection
Range(y, Range("O20")).FillDown

As per your your other reply, there is no need to select the range. The
following is the better code.

Set y = Range("F" & myLastFilledFormulaRow)
Range(y, Range("O20")).FillDown

However, you should realize that the above code only fills down. Your range
goes across to column O. If you want the entire range to be filled then you
need to FillRight also.


Set y = Range("F" & myLastFilledFormulaRow)
Range(y, Range("O20")).FillDown
Range(y, Range("O20")).FillRight

--
Regards,

OssieMac