View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Macro for Fill Down where number of rows differs and withouthaving to hardcode column ranges

On 29 Nov., 04:30, wrote:
Hi all

I am sure there is a very quick answer to my problem but it is outside
my limited knowledge of Excel Macro's.

I have a sheet that I import data to. Data is imported into the range
starting in cell A4 and across to column AZ. The number of rows
differs depending upon each export, but can be up to 50,000+

In Column BA:DZ I have a heap of calculations. Row 3 stores the
calculations. I currently have a very messy macro that fills down for
each and every column individually (if I select them all at once excel
has a hisssy fit) down to row 60000

e.g.

Range("BA3:BA60000").Select
Selection.FillDown

I know I can find out what is the last row with End(xlUp) etc and I
know I can put that in a variable

e.g.
Range("BA3:BA" & Range("A65536").End(xlUp).Row).Select
' Selection.FillDown

(column A will always have data in it where the remainder of the row
contains at least some info)

But how do I make it 'neat' so that anytime I add additional columns I
don't have to add a new line to the macro

In effect I want to repeat the same filldown starting at Column BA and
going through to DZ (or further if I add extra calculations - Row 1
has column titles where there is a calculation otherwise they are
blank where there is no info and therefore no fill).

Clear as mud?

Any tips would be greatfully received as I fear my brain is turning
rapidly into an excel mush

Cheers

David


Hi David

Try to look at this.

Application.ScreenUpdating = False
LastRow = Range("A4").End(xlDown).Row
LastColumn = Range("A3").End(xlToRight).Column
Range("BA3", Cells(LastRow, LastColumn)).Select
Selection.FillDown
Application.ScreenUpdating = True

Regards,

Per