+ Reply to Thread
Results 1 to 13 of 13

Macro - Replace Number with Specific text with formatting

  1. #1
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Macro - Replace Number with Specific text with formatting

    Hi All,

    I've tried to create somewhat of an interactive table look up. My aim is when I insert a value into a cell, I want the macro to find that value in a seperate sheet and override my initial entry, while bringing the cell formatting across. I hope that makes sense? I've attached an image as it may help.

    So ideally I was hoping this can be configured to automatically update the cell upon entry, is that possible?

    image.png
    Last edited by Roksman; 11-03-2016 at 12:55 AM.

  2. #2
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Probably best I add an "after" shot of what I'm trying to achieve. See pic.

    image-1.png

    Ideally I'd like to be able to continue adding values to the list. I'm planning to have over 400 entries.

    So once I input the numeric value, hit enter, it retrieves the value instantaneously once I move onto the next row.

    Appreciate any help. Thanks

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro - Replace Number with Specific text with formatting

    (How to) Upload a Workbook directly to the Forum
    (please do not post pictures or links to worksheets)
    • Click Advanced next to Quick Post button at the bottom right of the editor box.
    • Scroll down until you see "Manage Attachments",
    • Click the "Choose" button at the upper left (upload from your computer).
    • Select your file, click "open", click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Close the Attachment Manager window.
    • Click "Submit Reply"
    Note: Please do not attach password protected workbooks/worksheets
    Ensure to disable any Workbook Open/Autorun macros before attaching!
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Workbook attached.

    I've removed any sensitive data and included multiple tables similar to how intend to use this functionality.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro - Replace Number with Specific text with formatting

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by protonLeah; 11-03-2016 at 08:23 PM. Reason: corrected spelling mistakes

  6. #6
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Thanks Proton,

    This is fantastic and exactly what I was looking for!

    However I did notice something, when entering value "1", it actually returns item 10? I've tried to look at the code but cant find anything (very complex for me).

    Also, would it be hard for me to add extra tables? I thought I could add to the "header_1" list, dont think that's the right way though?

    Appreciate your efforts!

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro - Replace Number with Specific text with formatting

    Change: Set MatchVal = ItemNumbers.Find(Target.Value)
    To: Set MatchVal = ItemNumbers.Find(Target.Value, after:=ItemNumbers.End(xlDown))


    For point #2, I'm sorry but I forgot to mention that header_1, ... etc. are named ranges. Select each additional table and click Define Name on the Formula Menubar. When header 7 table is selected, Excel will then name that block of cells header_7. You can then add it to the code as Range("header_7"). Note that I put them in two columns just for easier reading. Each Range("header_x") is separated by commas.
    Last edited by protonLeah; 11-03-2016 at 08:40 PM.

  8. #8
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Wow, a tad embarrassing, was right in front of me.

    My other question is, how do I increase the table range? My sample file had 6 tables (headers) from column C to G, but I cant see anything that represents those columns? I'm currently trying to increase to 16 'Headers" - (8 on top, 8 on bottom as the sample format, instead of 3 and 3).

    My assumption is that the below controls that, but I unfortunately cannot figure this out.

    If Not Intersect(Target, _
    Union( _
    Range("header_1"), Range("header_2"), _
    Range("header_3"), Range("header_4"), _
    Range("header_5"), Range("header_6")) _
    ) Is Nothing Then


    I apologise if I should have just sent the intended range in the sample file.

  9. #9
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro - Replace Number with Specific text with formatting

    The original line is:
    Please Login or Register  to view this content.
    but it's too long to fit on the screen in the VB editor without having to scroll. So I used the "_" character break it into 5 shorter lines and wrap it to the next line down. You can delete the "_" at the end of each line and bring them all up to one line. The "_" at the end is a wordwrap code, it is not the same as the one here: "header_4".

    Just delete the "_" at the end of the line and continue to press delete until the following line moves up. (You could also just copy the line at the top of this post and paste it in. Then to add your new tables it will look like:
    Please Login or Register  to view this content.
    Last edited by protonLeah; 11-03-2016 at 09:43 PM.

  10. #10
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Thanks,

    I understand what you mean in regards to the word wrap. However, if I'm copying the data from Columns B to G, and pasting them in H to M (effectively just doubling my table area), adding header_6 to header_12 to the wordwrap isn't going to work is it?

  11. #11
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Just to clarify, the code obviously works on cells

    C2 to C23
    E2 to E23
    G2 to G23

    And

    C27 to C48
    E27 to E48
    G27 to G48

    Adding the headers to the word wrap alone won't enable that same behaviour to other columns will it? Do I have to identify which columns I intend to add? And which cells for that matter?

    I copied the existing Sample file from (B to G) and pasted in H to M, but simply adding the header numbers doesn't apply the logic to H2 to H23 etc

  12. #12
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Hi,

    Problem solved, I worked out how to extend the Range. Thank you very much for all your help. Much appreciated

  13. #13
    Registered User
    Join Date
    11-02-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro - Replace Number with Specific text with formatting

    Hi,

    I've been trying to enhance this script by including a duplicate validation alert (msg box pop up) but having difficulty adding it into the ranges.
    Appreciate any help.

+ 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] Macro to replace numbers with specific text value
    By Shayk in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-05-2016, 03:01 AM
  2. [SOLVED] Macro for find/replace specific text within a column
    By majkkali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2015, 10:59 AM
  3. Replace text to number with conditional formatting
    By MontrealMTL in forum Excel General
    Replies: 6
    Last Post: 07-27-2015, 09:52 AM
  4. Replies: 2
    Last Post: 04-10-2015, 12:12 PM
  5. Macro to find header information and replace with specific text
    By Nancy Taylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2013, 04:47 PM
  6. macro to replace specific data with column header text
    By wkilc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2010, 11:52 AM
  7. [SOLVED] Replace Number with Text using Macro
    By Carter68 in forum Excel General
    Replies: 3
    Last Post: 04-19-2005, 04: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