+ Reply to Thread
Results 1 to 9 of 9

Macro which searches for cell with text "Total Cost" and references cell 3 to the right

  1. #1
    Registered User
    Join Date
    11-26-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Macro which searches for cell with text "Total Cost" and references cell 3 to the right

    Hi,

    Thanks again for all of your help.

    Please help me create a macro that does the following. I will keep it in my personal macro workbook as I will need it across workbooks.

    Selects sheet "Summary" as the Active Sheet
    Selects cell D15 on the worksheet entitled "Summary"
    Search for the cell with the text "Total Cost" on sheet "Dec" and selects the cell exactly 3 cells to the right of that cell. (if cell with text "Total Cost" is Dec!B27, the cell I need is Dec!E27)
    Display the contents of the Dec!E27 in D15 of sheet "Summary"

    It would be a simple reference to Dec!E27, but the cell I want will not ALWAYS be in E27, and this will be for different documents every time, which is why I want it to search for it.

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    Hi SF1eagles, try this:
    Please Login or Register  to view this content.

  3. #3
    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
    44,461

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    One way:

    Please Login or Register  to view this content.

    There's no error handling so you might need something to check if Total Cost isn't there.

    Regards, TMS
    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


  4. #4
    Registered User
    Join Date
    11-26-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    Hi berlan,

    I am receiving the following error message: Run-time error '9': Subscript out of range

    I have attached the document, guys, thanks.

    TM, it works well, but, it does not paste the value into D15 on Summary, it only selects it. My macro is not perfect yet, but see below. I have another thread open for perfecting it:

    Please Login or Register  to view this content.
    Right now, I am strictly referencing a cell to put in D5 on Summary. I want instead to pull the cell based on the criteria above because the cell may never be in the same place across multiple workbooks.
    Last edited by SF1eagles; 01-31-2014 at 10:43 AM.

  5. #5
    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
    44,461

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    Thanks for the rep.

    it does not paste the value into D15 on Summary
    My code doesn't select anything.

    It sets the cell on the summary sheet equal to the value it found.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-26-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    No prob, that makes sense, however, I am still receiving the subscript error (I had edited my post, you may have missed it)

  7. #7
    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
    44,461

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    Please Login or Register  to view this content.

    Now includes some error handling in case the Total Cost is not found.


    Regards, TMS

  8. #8
    Registered User
    Join Date
    11-26-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    Hi,

    This is what I have right now - working well, except that I want your code to CHECK whether there is any COST in that cell, and then set D15 to the found value. This is because I am pasting data into the "Dec" sheet and so your code prematurely writes "no data" before I paste. I need the sequence to be:

    1) Duplicate "NOV" sheet
    2) Rename copy "DEC"
    3) Set C2 in "DEC" sheet to equal sheet name
    4) Clear "DEC" data between row 3 where Placement/Impressions/Clicks Recorded/Media Cost sits and the row where Total Cost sits (the latter is variable, as each Nov sheet I copy has a different number of rows, this clear is tricky)
    5) Once cleared, immediately assign a absolute formula in D15 on "Summary" to display the value (0,3) from "Total Cost" on "DEC"

    This may mean that the "found" function you created might not work. Thanks for the help! I have a project to complete, so I can't dig in to the code as much as I'd like to myself. I hate just giving directions, but appreciate the help!

    Please Login or Register  to view this content.

  9. #9
    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
    44,461

    Re: Macro which searches for cell with text "Total Cost" and references cell 3 to the righ

    Please Login or Register  to view this content.

    Your code needs to be generalised. At present, it will work only once to take a Nov sheet, make a Dec sheet, and insert a formula linking to the Dec sheet.


    Regards, TMS

+ 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] Equation which searches a cell for PM or P and replaces number after with an "x"
    By herbie226 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-03-2013, 06:20 PM
  2. Replies: 12
    Last Post: 10-15-2012, 03:57 PM
  3. [SOLVED] Macro to delete entire row if cell contains the word "total" or "Total"
    By theatricalveggie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2011, 12:38 PM
  4. Replies: 2
    Last Post: 10-08-2009, 09:58 AM
  5. Replies: 3
    Last Post: 02-04-2005, 08:06 PM

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