Consulting

Results 1 to 3 of 3

Thread: Solved: Apply formula to all cells in a column

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Solved: Apply formula to all cells in a column

    [VBA]Sub AlignText()
    '
    ' Align Text

    Range("AA5:AH5").Select
    Range(Selection, Selection.End(xlDown)).Select
    With Selection
    .HorizontalAlignment = xlLeft
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With

    End Sub[/VBA]

    How do i get this to apply to all cells in these columns?

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub AlignText()
    '
    ' Align Text

    With Range("AA5:AH5").Resize(LastRow(ActiveSheet, ActiveSheet.Range("AA5")) - 4)
    .HorizontalAlignment = xlLeft
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With

    End Sub


    Function LastRow(sh As Worksheet, StartAt As Range)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
    After:=StartAt, _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
    On Error GoTo 0
    End Function
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    XLD, This was too good.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •