excel autofill macro

  • Thread starter Thread starter angieg
  • Start date Start date
A

angieg

Can someone please help me figure out a macro that I can use to autofil
a formula into all the cells below it until the data on the lef
quits?
This is the situation:
I have several worksheets that I have to insert the followin
formula(="t"&right(b2,12)) to cell d2. The problem I need help with i
that sometimes I have to copy this down to row 42 and sometimes I hav
to copy this to row 5300. It varies with each workbook. Can someon
please help me? This small macro would save me hours of time eac
week.
Thanks in advance for your help!
 
Probably no need for a macro, try this,

Enter the formula in D2, then select D2 and double-click the fill handle (the
little black square in the bottom right corner of the cell).

HTH
Anders Silven
 
One small addition,

This will not work if column C is empty. If so, enter the formula in column C.

Anders Silven

Anders S said:
Probably no need for a macro, try this,

Enter the formula in D2, then select D2 and double-click the fill handle (the
little black square in the bottom right corner of the cell).

HTH
Anders Silven
 
Sub Auto_Fill()
Dim lrow As Long
With ActiveSheet
lrow = Range("B" & Rows.Count).End(xlUp).Row
Range("D2:D" & lrow).FillDown
End With
End Sub

Gord Dibben Excel MVP
 
Thanks to all for your fast response. I figured it out!! See cod
below. The reason I wanted a macro is because there are severa
columns that I needed to do this to 20 to 30 times a day, and typin
the same formula over and over gets soooo old. I'll definitely b
coming back here for more answers.

Angie

Sub autofill()
Dim LastRow As Long
With Worksheets("Sheet2")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("D2").autofill Destination:=.Range("D2:D" & LastRow) _
, Type:=xlFillDefault
End With
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top