+ Reply to Thread
Results 1 to 6 of 6

vlookup iserror with autofill to dynamic range - changing array/col index

Hybrid View

  1. #1
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,035

    Re: vlookup iserror with autofill to dynamic range - changing array/col index

    Code tags please, before I can provide a possible solution.


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  2. #2
    Registered User
    Join Date
    02-06-2014
    Location
    derby
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: vlookup iserror with autofill to dynamic range - changing array/col index

    Apologies, here is the same code with code tags. I wrote this after a day of staring at various code annoyances so I accidentally missed rule 3

    first off I apologise as I am struggling to explain what I want to do:

    I am trying to do vlookups (excel 2010) with the result of "unknown" if there is an error on a column of varying length, autofilling to the last row of adjacent column.

    The current code I have works fine, however I want to include this in a loop where the vlookup values/array/column index number change depending on which worksheet the value has been taken from. I have tried to use application.vlookup and application.worksheetfunction.vlookup in the past but autofill only fills the first value not its formula.

    current code
    
    Set myrange = Sheets("temp_for_calcs").Columns("c:c") 'setting range for countif of variable length column
    Sheets("temp_for_calcs").Select
    Range("d2").Formula = "=countif(b:b,c2)" 
    countnonblank = Application.WorksheetFunction.CountA(myrange) 
    
    Range("e2").Formula = "=IFERROR(VLOOKUP(c2,flag_matrix!A:be,57,FALSE),""unknown"")" ' <<<<<<<< here i want to edit so the a:be / 57 are replaced by variables v_array and v_index
    Range("f2").Formula = "=IF(e2<>""unknown"",d2*e2,""unknown"")"
    Range("i2").Formula = "=sum(d:d)" 'total flag count
    Range("g2").Formula = "=IF(e2<>""unknown"",d2/$i$2 *100,""unknown"")" '% of total score
    
    If countnonblank > 2 Then 'accounts for 1 value and column header, stops autofill error if no rows to fill
    ' fills to the end of data in row b
    '''CHANGE BELOW''' table array and column index number'
    Range("d2").AutoFill Destination:=Range("d2:d" & countnonblank)
    Range("e2").AutoFill Destination:=Range("e2:e" & countnonblank)
    Range("f2").AutoFill Destination:=Range("f2:f" & countnonblank)
    
    Range("g2").AutoFill Destination:=Range("g2:g" & countnonblank)
    
    End If


    any idea how I can use vlookup (including an 'unknown' on error) that I can assign preset values for the table array and index number that can be autofilled down a column of varying length?



    thank you for trying to understand my question!

  3. #3
    Registered User
    Join Date
    02-06-2014
    Location
    derby
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: vlookup iserror with autofill to dynamic range - changing array/col index

    Apologies, here is the same code with code tags. I wrote this after a day of staring at various code annoyances so I accidentally missed rule 3


    current code
    
    Set myrange = Sheets("temp_for_calcs").Columns("c:c") 'setting range for countif of variable length column
    Sheets("temp_for_calcs").Select
    Range("d2").Formula = "=countif(b:b,c2)" 
    countnonblank = Application.WorksheetFunction.CountA(myrange) 
    
    Range("e2").Formula = "=IFERROR(VLOOKUP(c2,flag_matrix!A:be,57,FALSE),""unknown"")" ' <<<<<<<< here i want to edit so the a:be / 57 are replaced by variables v_array and v_index
    Range("f2").Formula = "=IF(e2<>""unknown"",d2*e2,""unknown"")"
    Range("i2").Formula = "=sum(d:d)" 'total flag count
    Range("g2").Formula = "=IF(e2<>""unknown"",d2/$i$2 *100,""unknown"")" '% of total score
    
    If countnonblank > 2 Then 'accounts for 1 value and column header, stops autofill error if no rows to fill
    ' fills to the end of data in row b
    '''CHANGE BELOW''' table array and column index number'
    Range("d2").AutoFill Destination:=Range("d2:d" & countnonblank)
    Range("e2").AutoFill Destination:=Range("e2:e" & countnonblank)
    Range("f2").AutoFill Destination:=Range("f2:f" & countnonblank)
    
    Range("g2").AutoFill Destination:=Range("g2:g" & countnonblank)
    
    End If


    any idea how I can use vlookup (including an 'unknown' on error) that I can assign preset values for the table array and index number that can be autofilled down a column of varying length?



    thank you for trying to understand my question!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel VBA: changing hard coded column to dynamic range to autofill to last row
    By AishaSanz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2014, 11:40 AM
  2. [SOLVED] Using INDIRECT with a dynamic range name as the array in an INDEX formulae = #REF
    By Gandalf21 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-12-2013, 09:27 AM
  3. [SOLVED] Help with Array IF-ISERROR-INDEX formula
    By Leaoni in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-15-2012, 04:06 PM
  4. Dynamic or Variable Lookup array in INDEX, MATCH or VLOOKUP
    By kishor_c in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-16-2012, 09:46 AM
  5. Vlookup and autofill a dynamic range
    By ajay1967 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2012, 07:36 PM

Tags for this Thread

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