Consulting

Results 1 to 2 of 2

Thread: change the vlookup via a macro

  1. #1
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    165
    Location

    change the vlookup via a macro

    HI
    I have two work books first one called "RevalSummaryYTD0706.xls" Worksheet "RevalTodate and the second workbook called "RevalComparisonModel.xls" worksheet "YTD Reval-y"

    I am using a vlookup formula to take a value from column AD and row 8 "first work book"......(=ROUND(VLOOKUP($C8,'[RevalSummary YTD 0706.xls]RevalToDate'!$B$8:$AG$48,31,0)/1000,2) - and returning the value to the second workbook - worksheet "YTD Reval-y" - column K

    (=ROUND(VLOOKUP($C8,'[RevalSummary YTD 0706.xls]RevalToDate'!$B$8:$AG$48,32,0)/1000,2) - column L - (same above)

    However, each time i add a new column to the right of column AD for the next period "first worksheet", the "31" value stays the same - as you would expect it to i.e. ref to column 31 in the vlookup forumla.....

    Here is the question:

    Is it possible to amend the forumla via a macro to automatically update (what cell you are referrring in the vlookup - in our case 31) if a column is added to the right of "column AD" change"31" to "32" (see formula) and if it is deleted the do the opposite.........on the click of a macro button.
    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No need, use a formula of

    =ROUND(VLOOKUP($C8,'[RevalSummary YTD 0706.xls]RevalToDate'!$B$8:$AG$48,COLUMN('[RevalSummary YTD 0706.xls]RevalToDate'!AG2)-1,0)/1000,2
    ____________________________________________
    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

Posting Permissions

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