Closed Thread
Results 1 to 2 of 2

Need to insert formula to a variable number of rows

  1. #1
    edoc abv
    Guest

    Need to insert formula to a variable number of rows

    I am trying to copy a vlookup formula, using vba, down colum "U" to
    rows that vary in length every time a do this report (newCount is the
    variable amount of Rows). The main problem with my code is the first
    argument in the vlookup formula. It has to be in relative mode down
    colum "E" starting in row 2; hence x=count +1, X being the row in colum
    "E". Can some one help. Here is my code.

    Sub fillRange()
    Range("u2").Select
    Dim Count As Integer
    Dim newCount As Integer
    Dim fCount As Integer
    newCount = 215
    For Count = 1 To newCount
    x = Count + 1
    ActiveCell.Offset(Count - 1, 0) = "=VLookup($e&(x),'Program
    Lookup' _ !A2:L500, 5, False)"
    Next Count
    End Sub

    Thanks


  2. #2
    Tom Ogilvy
    Guest

    Re: Need to insert formula to a variable number of rows

    I assume E2 needs to be relative and A2:L500 should be absolute

    Sub fillRange()
    Dim newCount as Long
    newCount = 250
    Range("U2").Resize(newCount,1).Formula = _
    "=VLookup(E2,'Program Lookup'" _
    & "!$A$2:$L$500, 5, False)"

    End Sub

    --
    Regards,
    Tom Ogilvy


    "edoc abv" <isauroruvalcaba@sbcglobal.net> wrote in message
    news:1127703219.278104.119600@g47g2000cwa.googlegroups.com...
    > I am trying to copy a vlookup formula, using vba, down colum "U" to
    > rows that vary in length every time a do this report (newCount is the
    > variable amount of Rows). The main problem with my code is the first
    > argument in the vlookup formula. It has to be in relative mode down
    > colum "E" starting in row 2; hence x=count +1, X being the row in colum
    > "E". Can some one help. Here is my code.
    >
    > Sub fillRange()
    > Range("u2").Select
    > Dim Count As Integer
    > Dim newCount As Integer
    > Dim fCount As Integer
    > newCount = 215
    > For Count = 1 To newCount
    > x = Count + 1
    > ActiveCell.Offset(Count - 1, 0) = "=VLookup($e&(x),'Program
    > Lookup' _ !A2:L500, 5, False)"
    > Next Count
    > End Sub
    >
    > Thanks
    >




Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1