Results 1 to 11 of 11

Unable to arrive at dynamic & automated alternative to manual find & replace process

Threaded View

calantha Unable to arrive at dynamic &... 12-18-2013, 12:13 PM
Olly Re: Seeking Elegant Solution 12-18-2013, 12:17 PM
calantha Re: Seeking Elegant Solution 12-18-2013, 01:09 PM
Olly Re: Seeking Elegant Solution 12-18-2013, 02:05 PM
calantha Re: Unable to arrive at... 12-18-2013, 03:06 PM
Richard Buttrey Re: Seeking Elegant Solution 12-18-2013, 12:28 PM
calantha Re: Seeking Elegant Solution 12-18-2013, 01:09 PM
Olly Re: Unable to arrive at... 12-18-2013, 03:34 PM
calantha Re: Unable to arrive at... 12-19-2013, 03:17 AM
Olly Re: Unable to arrive at... 12-19-2013, 03:23 AM
calantha Re: Unable to arrive at... 12-19-2013, 03:55 AM
  1. #1
    Registered User
    Join Date
    04-01-2013
    Location
    Cambodia
    MS-Off Ver
    Excel for Mac 2011
    Posts
    9

    Unable to arrive at dynamic & automated alternative to manual find & replace process

    Hullo Excel Forum community!

    I've currently got an inelegant, manual, error-prone solution to a gnarly problem that I would appreciate a dynamic and automatic solution. As you'll see, I'm still a teeny noob when it comes to Excel, and I would sincerely appreciate any help I can get. Thank you so much!

    Setup

    I currently have 1 worksheet called 'Inputs-Yearly' that houses all of the inputs that change yearly. For example:
    B2 = price of diesel in 2013, C2 = price of diesel in 2014, D2 = price of diesel in 2015, etc.
    B3 = price of gas in 2013, C3 = price of gas in 2014, D3 = price of gas in 2015, etc.
    There are a total of 6 years (so columns B, C, D, E, F, G) and ~100 types of inputs (so rows 2, ..., 101)

    My current setup has 1 worksheet per year, totaling 6 worksheets. Each worksheet would call inputs from only one column of the 'Inputs-Yearly' tab. I start off with one worksheet for year 1, I plan on copying that worksheet 5 times, and doing a manual Find and Replace for all instances of 'Inputs-Yearly'!$B > 'Inputs-Yearly'!$C for year 2 (and D, E, F, G for years 3 through 6, respectively). This is an inelegant solution

    Ideal solution
    1. Not require me to manually Find+Replace; the input values would dynamically update in accordance to the year.
    2. Not have 6 copies of the same worksheet but 1 as any changes made to one I would have to copy over to the other five.
    3. Not have an unwieldy 2-line formula every time I call a cell reference to the input.

    My attempts

    Failed Solution #1:

    Dynamically update the year through CHOOSE, INDIRECT, CONCATENATE, and OFFSET.
    In L6 is 1 (the year #)
    In L7 is $C$2 (written as text, not cell reference; 'Input-Yearly'!$C$2 is the input from Year 1 I've called 800+ times in the worksheet for year 1)

    In L8 is =CHOOSE($L$6,INDIRECT(CONCATENATE("'Inputs-Yearly'!",L7)),OFFSET(INDIRECT("'Inputs-Yearly'!",L7),0,1,1,1),OFFSET(INDIRECT("'Inputs-Yearly'!",L7),0,2,1,1),OFFSET(INDIRECT("'Inputs-Yearly'!",L7),0,3,1,1),OFFSET(INDIRECT("'Inputs-Yearly'!",L7),0,4,1,1),OFFSET(INDIRECT("'Inputs-Yearly'!",L6),0,5,1,1),OFFSET(INDIRECT("'Inputs-Yearly'!",L7),0,6,1,1))

    This does dynamically update the year. However, there are ~100 types of inputs (C2, C3, C4, C5, all the way to C100) and I'd have to do a Find+Replace 100x.

    Failed Solution #2:
    Run a Find+Replace:
    Find: 'Inputs-Yearly'!$C$2
    Replace: INPUTFORYEAR($C$2)
    INPUTFORYEAR == CHOOSE($C$2, 'Inputs-Yearly'!$D$10, 'Inputs-Yearly'!$E$10, 'Inputs-Yearly'!$F$10, 'Inputs-Yearly'!$G$10, 'Inputs-Yearly'!$H$10, 'Inputs-Yearly'!$I$10)

    So I wrote the following VBA code (mind you, I've never coded a single line of VBA code in my life before):

    Public Function INPUTFORYEAR(model_input As Range, model_year As Number) As Range
     '  model_input would be the cell reference to a particular hard-coded input within the "Input-Yearly" tab that corresponds to a Year 1 input
     '  model_year would be 1, 2, 3, 4, 5, or 6
     '  INPUTFORYEAR would take in the two arguments above and output the hard-coded input not for Year 1, but for the model_year
        Application.WorksheetFunction.Choose(model_year, Application.WorksheetFunction.Offset(model_input, 0, 1, 1, 1), Application.WorksheetFunction.Offset(model_input, 0, 2, 1, 1), Application.WorksheetFunction.Offset(model_input, 0, 3, 1, 1), Application.WorksheetFunction.Offset(model_input, 0, 4, 1, 1), Application.WorksheetFunction.Offset(model_input, 0, 5, 1, 1), Application.WorksheetFunction.Offset(model_input, 0, 6, 1, 1))
        End Function
    Two issues:
    1. There are ~100 types of inputs (C2, C3, C4, C5, all the way to C100) and I'd have to do a Find+Replace 100x.
    2. I've made a mistake somewhere in the VBA code and keep getting error messages.

    SO,

    *heaves a sigh* can anyone proffer a more elegant solution that would dynamically update input values a la the year and not have a huge 2-line formula every time I call the input value -- all within 1 tab?

    Thank you thank you thank you!!!

    Calantha
    Last edited by calantha; 12-19-2013 at 03:28 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Looking for a more elegant solution with CountIf to evaluate formats
    By fitzt70 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-18-2013, 03:01 AM
  2. Textbox validation - is there a more elegant solution?
    By madbloke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2009, 08:03 AM
  3. More Elegant solution to function submitting
    By Mat_Davies in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-16-2009, 09:06 AM
  4. [SOLVED] Is there an elegant solution to this table?
    By uberyes@gmail.com in forum Excel General
    Replies: 3
    Last Post: 07-10-2006, 03:29 AM
  5. Working Hours (formula & graph) - any elegant solution?
    By markx in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-29-2006, 09:10 AM

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