Consulting

Results 1 to 5 of 5

Thread: VBA Code to populate to end of data

  1. #1
    VBAX Regular
    Joined
    Mar 2013
    Posts
    51
    Location

    VBA Code to populate to end of data

    Hi all,

    I am working on a VBA code that I would like to have run data to the end of rows in a column. The number of rows change with every different spreadsheet that I would like to run the vba code on. Here is my code:

    ActiveCell.FormulaR1C1 = "ISM"
    Range("H2").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(RC[-1],'Custom Input Symbols_2013-09-18 103538.csv'!C1:C3,3,FALSE)"
    Range("H2").Select
    Selection.AutoFill Destination:=Range("H500").End(xlUp)

    How do I get this code to run to the end of each worksheet? What do I add/change? Thanks in advance!

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    untested (only two lines needed I think):
    ActiveCell.FormulaR1C1 = "ISM"
    Range(Range("H2"),Range("H2").end(xldown)).FormulaR1C1 = "=VLOOKUP(RC[-1],'Custom Input Symbols_2013-09-18 103538.csv'!C1:C3,3,FALSE)"
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Mar 2013
    Posts
    51
    Location
    Hi p45cal,

    I tried your VBA code that you suggested about how to get the code to run a vlookup to the bottom of my data in column G, where the vlookup in in column H. The problem is, the VBA code runs to the very bottom of the worksheet. How do you make the VBA code run to only the last row in column G so that the vlookup in column H stops at the very last row of data in column G? It would also be great if the word "ISM" could be in H1 which would be above the vlookup output. Thanks for your help.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Range("H1").value = "ISM" 
    Range(Range("G2"),Range("G2").end(xldown)).offset(,1).FormulaR1C1 = "=VLOOKUP(RC[-1],'Custom Input Symbols_2013-09-18 103538.csv'!C1:C3,3,FALSE)"
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Regular
    Joined
    Mar 2013
    Posts
    51
    Location
    Great! The new VBA code works! Thanks alot for your help.

Posting Permissions

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