VBA Code

B

BMistry

Hello,

I have recently started using VB for my excel sheet by
recording a macro and manipulating the code. However, I'm
stuck with a problem which I am hoping someone will be
able to help me with.

In my macro, I insert a column and then a formula on the
first line. Then I double click on the right hand side of
my cell which copies the formula to the bottom of all my
records. However, when i look at the coding it put the
copying as an absolute value ie. F2:F2555. As my data is
being pulled through a ODBC link and is dependant on the
date field (the user can enter a date range for the
report) the number of records it will bring up will be
different every time. Is there anyway, I can change the
code so it copies the formula to all records no matter how
many there are.

I do not want the formula to be copied into cells with
empty records as I will be using the info to create a
pivot table afterwards.

Any help will be much appreciated.

Thanks

B
 
C

Cecilkumara Fernando

BMistry,
You can find the Last Row of data in columnE with

LastRow = Range("E" & Rows.Count).End(xlUp).row

and use it for autofill

Range("F2").AutoFill _
Destination:=Range("F2:F" & LastRow)

HTH
Cecil
 
Top