Consulting

Results 1 to 5 of 5

Thread: Solved: Filling a formula

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

    Solved: Filling a formula

    [VBA]Sub bloomberg()
    '
    ' bloomberg Macro
    '
    '
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=BDP(RC[-1]& "" muni"",""id_cusip"")"
    Range("F2").Select
    Selection.AutoFill Destination:=Range("F2:F1000")
    Range("F2:F1000").Select
    End Sub[/VBA]


    As you can see, this macro fills the formula from F2 to F1000. However, I want it to fill only how many rows are in column F. There could be 2 rows or 100 rows. How to I create a general macro to fill column F?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I'll tell you when you add VBA tags.
    ____________________________________________
    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
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    [VBA]Sub bloomberg()
    '
    ' bloomberg Macro
    '
    '
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=BDP(RC[-1]& "" muni"",""id_cusip"")"
    Range("F2").Select
    Selection.AutoFill Destination:=Range("F2:F1000")
    Range("F2:F1000").Select
    End Sub[/VBA]

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Excellent, thank-you.

    [vba]

    Sub bloomberg()
    '
    ' bloomberg Macro
    '
    '
    Dim lastrow As Long

    lastrow = Cells(Rows.Count, "E").End(xlUp).Row
    Columns("F:F").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F2").Resize(lastrow - 1).FormulaR1C1 = "=BDP(RC[-1]& "" muni"",""id_cusip"")"
    End Sub
    [/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

  5. #5
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    Thank you!

Posting Permissions

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