Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill from active cell to last row 1

Status
Not open for further replies.

Evil8

MIS
Mar 3, 2006
313
US
I need to insert a formula from the active cell down the column to the last row. My problem is with the last line of code below.

I have:
Code:
Sub ClientName()
' SepatateName Macro
' Create first name and last name from full name.
'
 Dim LastRow As Long, r As Long        'Last Row
 Dim NCol As Long                      'Client Name Column

  'Find the LAST real row
    LastRow = ActiveSheet.Cells.Find(What:="*", _
      SearchDirection:=xlPrevious, _
      SearchOrder:=xlByRows).Row
'

    NCol = Cells.Find(What:="Client Name", SearchOrder:=xlByColumns, MatchCase:=True).Column
    Columns(NCol).Select
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
    Range(Selection, Selection.Columns(4)).EntireColumn.Select
    Selection.ColumnWidth = 20
    ActiveCell.FormulaR1C1 = "Last Name"
    With ActiveCell.Characters(Start:=1, Length:=9).Font
        .Name = "Arial"
        .FontStyle = "Bold"
    End With

    ActiveCell.Offset(1, 0).Select
    ActiveCell.Formula = "=LEFT(RC[+4],FIND("","",RC[+4])-1)"
    Selection.AutoFill Destination:=Range([COLOR=red]ActiveCell[/color] & LastRow), Type:=xlFillDefault

    
End Sub

All your help is appreciated.

Evil8
 
The syntax for a range is range(cell1,cell2). lastrow is a row number. The corresponding column number is, I believe, the column number of activecell:
Code:
colnum=activecell.column
that is, if you want to perform this all on a single column.
So, I think you need:
Code:
Destination:=Range(ActiveCell,cells(LastRow, activecell.column))

_________________
Bob Rashkin
 
That worked perfectly. Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top