+ Reply to Thread
Results 1 to 14 of 14

Macro to find and replace specific strings in a cell link by using cell references

  1. #1
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Macro to find and replace specific strings in a cell link by using cell references

    Capture.JPG
    Screenshot of example rows

    Spreadsheet file: Test Training Sheet.xlsx

    This is the macro that I first recorded with relative references:

    Please Login or Register  to view this content.
    My goal is to have, say, Row 1 be the example row that would be copied into all other rows. The only difference would be the name in Columns B and C. This name corresponds to the links in the cells like so:

    Please Login or Register  to view this content.
    I would want the macro or code to look through and change "Billy Bob" to whatever is entered into the B cell of that row. The name in each row is linked to it's own spreadhsheet. All the cells in the row pull from that individual spreadsheet, so their links need to correspond to the name in the B cell.

    However, I can't get my macros and vba code to work and would greatly appreciate any assistance or advice!

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Macro to find and replace specific strings in a cell link by using cell references

    try amending the following code to suit your needs:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Re: Macro to find and replace specific strings in a cell link by using cell references

    Thank you so much! However, when I run the macro, nothing happens. Should I be selecting certain cells before running? I ran it on the whole sheet and on a selection of all the columns separately and both times nothing occurred.

  4. #4
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Re: Macro to find and replace specific strings in a cell link by using cell references

    Additionally, the $E$2 in the link is only for that cell/column. All the other columns of D-M reference other cells in the linked sheets such as $I$2.

    Would there be a lot of editing required to accommodate this in the code?

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Macro to find and replace specific strings in a cell link by using cell references

    However, when I run the macro, nothing happens.
    Trust you have saved the file as XLSM (macro-enabled workbook) and not XLSX format before running the macro. Let me know if it still doesn't run.

    All the other columns of D-M reference other cells in the linked sheets such as $I$2.
    For this, populate a few rows with the expected result so one can see a progression.

  6. #6
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Macro to find and replace specific strings in a cell link by using cell references

    I read your sample workbook
    I need explanation, for ex:

    In cell D3, the formula is: ='G:\DINING\64 Degrees Student Manager\Training\Students\[64 Template - Copy.xlsx]Sheet1'!$E$2
    Do you want it to become: ='G:\DINING\64 Degrees Student Manager\Training\Students\[Billy Bob.xlsx]Sheet1'!$E$2

  7. #7
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Re: Macro to find and replace specific strings in a cell link by using cell references

    Correct. Billy Bob because it is in the corresponding B cell for that row. In the next row below, it would be Joanne Sue. Each name in Column B, such as Billy Bob, corresponds to a spreadsheet of the same name, Billy Bob.xlsx. That way, each named spreadsheet is linked to the cells of that row.

  8. #8
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Macro to find and replace specific strings in a cell link by using cell references

    Ok, another question
    In cell C3, the formula is: =HYPERLINK("G:\DINING\64 Degrees Student Manager\Training\Students\64 Template - Copy.xlsx"&B3&"'!A1";B3)
    Do you want it to become:
    =HYPERLINK("[G:\DINING\64 Degrees Student Manager\Training\Students\Billy Bob.xlsx]Billy Bob!A1";B3)
    it means there's a sheet name Billy Bob in the workbook Billy Bob
    or
    =HYPERLINK("[G:\DINING\64 Degrees Student Manager\Training\Students\Billy Bob.xlsx]sheet1!A1";B3)

  9. #9
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Re: Macro to find and replace specific strings in a cell link by using cell references

    That was the result of my tinkering. In my actual workbook, the formula is as follows:

    =HYPERLINK("G:\DINING\64 Degrees Student Manager\Training\Students\Billy Bob.xlsx",B3)

  10. #10
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Macro to find and replace specific strings in a cell link by using cell references

    Try this :
    Macro 'insertAll' is to insert cell refrencere in column D to M in all rows that already has data (Names)

    Macro 'insertOne' is to insert cell refrencere in column D to M in one row, that is if you type new data in column B. Notes: after you finish typing the name use right arrow (not enter) then run the macro, it's because the macro needs the cursor still in that row.
    You can assign this macro to a keyboard shortcut, in case you need it frequently.

    For hyperlink in column C, copy this formula to C3 then copydown.
    Please Login or Register  to view this content.
    You can change the path of the workbook if you need to (see the code line in red).
    Please check the sequence of cell reference in column D to M, in case I got it wrong.


    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Re: Macro to find and replace specific strings in a cell link by using cell references

    ***Update***

    The code works! Great! However, it occasionally will get to a row and cause a #REF! error in the cells of that row. I have realized that it is because it adds a space at the end of the file name. So, instead of Billy Bob.xlsx, it inserts Billy Bob. xlsx which causes the error. The majority of the rows work in spite of this. Any idea as to why it does this?



    I can see that this will be a great help once I can get it functioning.

    However, when I run the macro Insert All, a dialog box pops up asking me to update values. I select the appropriate spreadsheet with the name in that row, but it pops up with the same box for every single cell in the row. This continues in all subsequent rows.

    Is there a way to have the links edited without having to do anything other than running the macro? All the files that the links reference exist, so there shouldn't be an error. It would just be extremely time consuming to have to re-select the same file over and over.
    Last edited by beginningcoder; 02-15-2016 at 08:07 PM.

  12. #12
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Macro to find and replace specific strings in a cell link by using cell references

    So, instead of Billy Bob.xlsx, it inserts Billy Bob. xlsx which causes the error.
    Is it 'Billy Bob. xlsx' or 'Billy Bob .xlsx'? I guess it's 'Billy Bob .xlsx'
    However, when I run the macro Insert All, a dialog box pops up asking me to update values
    I modified the macro to address both issue, let me know how it works.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-13-2016
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    9

    Re: Macro to find and replace specific strings in a cell link by using cell references

    Thank you so much for your help.

    Upon further inspection, I realized that the problem rows had spaces after the name entries in Column B. I realized that the macro was functioning correctly, but the name that it was putting into the links had the space in it.

    However, there was one name that just would not work. The file it referenced existed and all the names were written correctly with no spaces. The only way it worked was if I re-created the entire row after deleting the original.

    Any ideas as to why this happened?

  14. #14
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Macro to find and replace specific strings in a cell link by using cell references

    I don't know why. And it's only happen to one name? What's the name?

+ 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] Help with macro to find a specific word and replace the entire cell with the return word.
    By BG1983 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-24-2015, 09:40 PM
  2. Replies: 1
    Last Post: 04-12-2015, 10:33 AM
  3. [SOLVED] Find and Replace - locking cell references
    By Terri Earley in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-15-2014, 12:09 PM
  4. Macro to find all specific values in column and replace adjacent cell values
    By dblock02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2013, 06:03 AM
  5. [SOLVED] Find and replace to specific cell content
    By xbr088 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2013, 03:59 PM
  6. Extract specific strings within a cell macro
    By ardniw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2013, 03:41 AM
  7. Using Find & Replace to edit cell references in links
    By Matt7102 in forum Excel General
    Replies: 0
    Last Post: 03-15-2006, 04:55 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