Consulting

Results 1 to 9 of 9

Thread: Is there a Simple Way to code this.

  1. #1

    Is there a Simple Way to code this.

    Folks, On the attached jpeg is a simple query. How would I code it to copy the formula in B2 down to B6. The number of rows will vary each time the the code is run.
    Attached Images Attached Images

  2. #2
    Maybe
    Sub Fill_It()
        Dim lr As Long
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        Range("B2:B" & lr).FillDown
    End Sub

  3. #3
    VBAX Regular
    Joined
    Nov 2011
    Location
    Ufa
    Posts
    75
    Location
    something like this
    Sub ttt()
    Dim SearchRange As Range
    Set SearchRange = Range("G1:I12") 'just for example
    With Range("B2:B" & Cells(Rows.Count, 1).End(xlUp).Row)
        .FormulaR1C1 = "=VLOOKUP(RC[-1]," & SearchRange.Address(, , xlR1C1) & ",3,0)"
    End With
    End Sub

  4. #4
    Jolivanes, Thanks that works a treat, simple when you know how.
    How does it work. Does the line "lr = Cells(Rows.Count, 1).End(xlUp).Row" Look right down col A to the very bottom to find the last cell with something enetered?

  5. #5
    Nilem, Thanks I guess your solution would work as long as the search range you specify would encompass the largest reasonable area you would expect a cell to be entered into.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by LutonBarry View Post
    How does it work. Does the line "lr = Cells(Rows.Count, 1).End(xlUp).Row" Look right down col A to the very bottom to find the last cell with something enetered?
    Yes it does because of the "rows.count, 1" and the .End(xlUp) requirements.
    Last edited by Bob Phillips; 11-20-2015 at 05:35 AM.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Thanks.
    So the .End(xlUp) tells it to go to the bottom and return back up to the first occupied cell?

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No, the Rows.Count tells it to go to the bottom, the End(xlUp) tells it to then go up until it hits a cell with a value.
    ____________________________________________
    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

  9. #9
    xld, Got it now thanks.

Posting Permissions

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