+ Reply to Thread
Results 1 to 18 of 18

Autofilling and concatenating info onto a main sheet from a data sheet

  1. #1
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Autofilling and concatenating info onto a main sheet from a data sheet

    I'm trying to make more efficient an Excel task that involves a lot of manual entry, but the information, though many different types, is consistent once used. For example, if I type the first however-many characters of a language string (like SQL, example, and typing up until it differentiates from similar strings), I want it to fill-in the brief "layman" explanation of what it's doing.

    I envision putting it on separate tab (that I will ultimately hide) and that I can transfer/copy for the hundreds of workbooks I need to complete. Think like a vlookup or index/match scenario (except doesn't put your results into a different cell, if possible) meets autofill world (except, since you "can't remember" the verbiage you used 20 workbooks ago, you're not filling in completely what you're typing, but the "layman" equivalent. A drop down won't work either, since you are typing what you are copying in front of you, but looking for what you have entered EXACTLY for that particular language string 20 workbooks ago.)

    I'm thinking, on that separate interchangeable tab from workbook to workbook that have the language string in Column A, and then the layman explanation in Column B, and constantly keep adding to it. But here's the kicker: I want to have the results all in one large, text-wrapped cell, and like SQL language that is separated by parentheses for specific actions, but CONNECTED by And's (&) and Or's (|), I want the layman explanations to read the same way. (?) are 'is", (~) is "contains", (!) is "not".

    For example, this is what I'm typing (essentially the info from my hypothetical Column A): sec_class~('CP') & sec_group!?('XYZ') to fill-in from the hidden worksheet, from Column B, (Sec Class contains CP) AND (Sec Group is not XYZ). So, see below what I'm thinking for Col A and Col B entries (unless you can think of a better system):

    Essentially, as I type the following string, with each component separated by "[]":

    [sec_class~('CP')][ & ][sec_group!?('XYZ')]


    to read:

    (Sec Class contains CP) AND (Sec Group is not XYZ)

    in the large, text-wrapped box.

    Now that I'm thinking about the functionality and limitations of Excel (prove me wrong, experts!), I may have to type the language in one area, and have the results (layman explanation) end up in my ultimate large, text-wrapped cell (THE ONE THAT WILL BE VIEWED). This can be on the same page off to the side, or on an "Entry" tab (perfect world I'd love to have in the same cell if feasible).

    Appreciate!
    BWR

  2. #2
    Registered User
    Join Date
    12-17-2016
    Location
    South Wales
    MS-Off Ver
    Excel 2007, 2016
    Posts
    68

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    This isn't a full solution, but a couple of thoughts for same cell changes. In both cases you'd need to work out in advance what might need to be changed - although for the first you'd need a complete list, whereas the second might work with more generic set of rules.

    Option 1 - use the Autocorrect functionality. There's a list of things that excel amends as you type. For example, a c in brackets is automatically changed to a copyright symbol. You can add to the autocorrect list, either "permanently", or you could have macros set for the Open and Close events that added items to the list on opening, and removed them on closing.

    Option 2 - use a Change event macro. You can build a check into the start of the macro so that it only triggers when a cell in a specific range is changed. The macro would apply the various rules you define to the cell value.

    Does either of these sound feasible? If so, I can put together some sample macro code. I think the trickiest bit may be defining a comprehensive set of "rules"?

  3. #3
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    bwr,

    You can use a series of Replace function code line paying particular attention to the order of replacements. These would serve as rules Trevor speaks of. In this example, Place the SQL line in cell A1 then run the code. You can replace Range("A1") with looping cells if needed.

    HTH,
    Maud

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Trevor/Maud-

    I like where we're going with this.

    Trevor S-
    Not sure that I get the concept of Option 2, but with Option 1, if it's similar to modifying the existing AutoCorrect, I think this does everything in the same cell, this seems like a good route. I would just want this task-specific AutoCorrect to be for these type of workbooks only, and not my other Excel activities outside of this scope.

    Maud-
    Ran your macro and worked flawlessly. Please explain the "looping cells" concept.

    Thanks,
    Brian

  5. #5
    Registered User
    Join Date
    12-17-2016
    Location
    South Wales
    MS-Off Ver
    Excel 2007, 2016
    Posts
    68

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    This page: https://msdn.microsoft.com/en-us/lib.../ff840663.aspx shows how to modify (adding to and deleting from) the existing autocorrect using a macro. So you could have a macro add the extra items to autocorrect when that workbook is opened, and remove them again when it is closed. The question is more whether you can define a set of corrections that don't impact on each other. For example, a [ appears to be treated differently depending upon whether its followed by an & ...

    My "option 2" is along the same lines as Maud's macro. The only difference is that I'd been considering using the Worksheet Change event (see examples here: https://msdn.microsoft.com/en-us/lib.../ff839775.aspx ), so that the changes would be automatic, rather than needing to run the macro. However, it may be better to see what you've typed, and then "translate" it, rather than it happen automatically?

  6. #6
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Please explain the "looping cells" concept.

    bwr,

    If you had a column of strings, say in column A, that you wanted to convert, you can use the same code but "loop" through the strings converting cell A1, then A2, then A3, ....

    This is best achieved by placing the code on a For...Each or a For...Next loop.

    Hope this code explains it,
    Maud

    Please Login or Register  to view this content.
    Last edited by Maudibe; 02-22-2017 at 12:48 AM.

  7. #7
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Trevor/Maud-

    Great efforts from you both. Advancing along efficiently, so appreciate the work. Just a few more tweaks, and I think I'll have it where I want it.

    1) Went with Replace method vs the Autocorrect (the latter being what I thought I originally wanted, but decided against because a) unlike Replace macro, I have to basically retype everything anyway vs cut/paste/run macro and was not efficient and b) if I don't Delete Replacement in AutoCorrect after Add Replacement, it seems the Autocorrect is permanent even in other new books and in cells/contexts I don't want it to AutoCorrect.

    2) The code, Maud, worked perfectly, but I just have one issue: I need the last character in the cell (essentially, the end of SQL formula) to end with a closed parentheses ")". I figured the open parentheses "(" into the other lines of the code, but because each string of code ends uniquely, and can't figure out a way to close the string automatically. My string of code could end with a letter, a number, an apostrophe, etc, and there's no constant. Is there a way, using the sample code above for Replace, to have the absolute last character be a ")", essentially the last line of my Range code?

    3) And Trevor, along the lines of your thinking, yes, I want it to be automatically run, but yes, I will want to proofread too for any minor adjustments. But I'm assuming, that once the macro has run, I can just go and check it (meaning it won't alter again, unless I rerun the macro?). I'm in the process of incorporating the color changes, so thanks for that. But to you both (or anyone), I want it to run in the entire workbook. Cell B11 is the same location on all of the sheets/tabs of a workbook, so I just want to run the macro once, and if the workbook has 27 sheets, run the Range macro automatically for all sheets, simultaneously, and then do my proofread. Correct me if I'm wrong, Maud, but the code above basically just does Cells A1-A10 for the sheet I'm on, and I need all of Range code to be run for all cells B11 within a given workbook.

    4) What does an asterisk "*" do in code? Is it a wildcard, or character replacement?

    Thanks again for the info and the progress, and in advance of the continued efforts.

    BWR

  8. #8
    Registered User
    Join Date
    12-17-2016
    Location
    South Wales
    MS-Off Ver
    Excel 2007, 2016
    Posts
    68

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    2) yes, you can add a line to the end of the macro to add a ")". I'm assuming that you want to check that it isn't already there, rather than add it regardless?

    3) By automatically running, I meant as soon as any change in the cell was made. But as you're dealing with so many sheets, may be better to have it as a macro to trigger when you want to ... but just get it to do all sheets when it runs. I'm assuming that there won't be any element as a the result of the "first run" that would then be changed again in a second run?

    4) yes, the * is a wildcard.

    Based on all this, I've amended Maud's code below.

    Please Login or Register  to view this content.
    I've built in the ability to exclude sheets if you need to. Just uncomment (by removing the first ') the "if..." and "end if" lines, and change the sheet names to exclude. I've written it to exclude two sheets, but you can adapt the line to exclude more or fewer sheets.
    Last edited by Trevor_S; 02-25-2017 at 03:43 AM.

  9. #9
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Nice tweak Trevor!

    Maud

  10. #10
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Trevor (or Maud)-

    Pure awesomeness with the tweaks to Maud's thread. Flawlessly, including the exclude sheets, as I had two hidden sheets that were not to be changed. As an additional caveat to sheets that I knowingly want to exclude, there are sheets that I unknowingly want to INCLUDE, but have blanks in cell B11 (targeted cell in the code above), but DO NOT want to add the ")", and simply want leave blank if they don't have anything there to begin with. Can we tweak that If Right line, or add an additional line if B11 is blank to leave blank?

    Thanks!
    BWR

  11. #11
    Registered User
    Join Date
    12-17-2016
    Location
    South Wales
    MS-Off Ver
    Excel 2007, 2016
    Posts
    68

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Just add an extra bit to the FIRST If... line. It will now skip the sheet if its specified as one to be excluded, or if B11 is blank:
    Please Login or Register  to view this content.
    Last edited by Trevor_S; 02-27-2017 at 03:00 PM.

  12. #12
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Trevor-

    "bit" as in an extra space, or as I would a sheet in the form of 'IF B11=""' or 'IF B11=0'? Please define "bit". Thanks!

    BWR

  13. #13
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Got it. For whatever reason, your string didn't come through upon first review. Thanks.

    BWR

  14. #14
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    bwr,

    How about this alternate tweak? Skip sheets whose tab color is red. No need to alter code to add skip sheets.

    Please Login or Register  to view this content.
    Maud

  15. #15
    Registered User
    Join Date
    02-14-2017
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    12

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Appreciate, Maud. I'll definitely use, as I always color code my tabs, but in this instance, I have a finicky end recipient that loves consistency and I guess, just plain vanilla, so it will just cause for many questions as to why are the tabs a different color.


    Alright, Trevor or Maud (or anyone), we've got our tightest model yet, and though I would have gathered all inquiries for you at once, always never the case. Now, my biggest issue (and one that I want to dig in deeper) is the previously discussed "*", or wildcard.

    1) I guess, first and foremost, does an "*" have to represent EACH missing character, or can it represent a series of characters in between? (This may answer a lot).

    2) My current dilemma is that with all of my rules, and appropriately placing them top to bottom is that some rules are grouped together, to be included together when put in the following format: "!($FOX_TROTS=ABCD & $FOX_TAILS=WXYZ)" to read "((Fox Trots is not ABCD) AND (Fox Tails is not WXYZ))" whereas:

    a) "!" means "not", or written out "is not";

    b) "&" (or "AND") can be substituted with "|" (or "OR"), hence my use of wildcards ("*") to get the characters and spaces in between the core rules;

    c) "$FOX_TROTS" and "$FOX_TAILS" can be substituted with any of handful of substitutions (such as "DEER_FEET" and/or "TURTLE_SHELLS"), but generally speaking the two formers go together when used;

    d) "ABCD" and "WXYZ" can be any of a huge list of identifiers, of any amount of characters, in no particular order, and not necessarily used together;

    e) and most of the time, there will be just two paired together (i.e., FOX_TROTS and FOX_TAILS), but sometimes there can be three or more of any combinations (i.e., FOX_TROTS, FOX TAILS, DEER_FEET)

    When I use "!($FOX_TROTS=ABCD & $FOX_TAILS=WXYZ)" , I currently run the macro and get !(Sec Group is FUND) AND (Sec Class is STIF) ,so I'm close. And then in the macro (below the initial strings, near the end), I try to run cell = Replace(cell, "!(Sec Group is*Sec Class is *)", "((Sec Group is not ""(Sec Class is not ""))", , , 1) and it doesn't do anything. I think I am simply using the wildcards incorrectly.


    But I have to watch what I do with the "!", and where I place it anywhere in the macro (unless I use it with a specific string of other characters), because although it always means "not" or "is not", it's never consistently placed in a string (could be at the beginning, as in the aforementioned case, or also in the middle of a string, depending on where the programmer puts it. It just basically states whatever is being used, it is NOT the case (or the opposite).

    Thank you for your continued feedback and efforts,
    BWR

  16. #16
    Registered User
    Join Date
    12-17-2016
    Location
    South Wales
    MS-Off Ver
    Excel 2007, 2016
    Posts
    68

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Ok... not a full answer yet, but a start!

    1) Wildcards - * is any number of characters. Use a ? for a single character. And if you need to find an actual * or ?, preceded it with a ~ symbol.

    2a) that's a tricky one, because in your example the ! isn't next to the =, so somehow you need to tie the two together. I'll need to give that more thought. We need to consider the syntax provided by the brackets.

    2b) More straight forward ... use a line similar to the & to AND line for | to OR. With any of these lines, there's no problem if the string that the line is looking to change can't be found.

    2c) Should be possible to do using wildcards and the Proper function (converts the case of text to lower with a capital for each initial. I'll try to work out some coding.

    2d) Shouldn't be a problem, as that part of the string should be left untouched. Only problem I can see would be if that string contained one or more of the "special" characters ($!_=&|) that we're trying to convert elsewhere.

    2e) Shouldn't be a problem, the macro should be able to convert all occurances found.

    I will look further into this, but maybe a couple of days before I get much chance, so if you manage to work anything out in the meantime, please keep the thread updated.

  17. #17
    Registered User
    Join Date
    12-17-2016
    Location
    South Wales
    MS-Off Ver
    Excel 2007, 2016
    Posts
    68

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    Some more code lines that you may want to consider adding some of to the previous code - looking mainly at cases. Order is again important!
    Please Login or Register  to view this content.
    This still doesn't do everything! I'll next try to look at how to deal with negated brackets - i.e. how "!(A=B [&] C=D)" can become "A is not B AND C is not D"

  18. #18
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Autofilling and concatenating info onto a main sheet from a data sheet

    no need to loop:

    Please Login or Register  to view this content.
    replaces all texts between brackets in the whole worksheet



+ 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. Replies: 6
    Last Post: 07-18-2013, 02:34 AM
  2. [SOLVED] Bulk import. (Copy Data from one sheet to a main sheet with conditions)
    By DanzaNZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2013, 12:24 AM
  3. Replies: 1
    Last Post: 02-13-2013, 01:32 PM
  4. [SOLVED] How to show info from main sheet to a a new sheet.
    By hendrikbez in forum Excel General
    Replies: 7
    Last Post: 10-12-2012, 04:21 AM
  5. [SOLVED] Pulling data from a main sheet and placing it onto a newly created sheet
    By cbomination in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 05-25-2012, 10:12 AM
  6. Replies: 15
    Last Post: 01-03-2012, 02:39 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