+ Reply to Thread
Results 1 to 23 of 23

Need a macro that allows me to place text across multiple columns? (Excel example included

  1. #1
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Need a macro that allows me to place text across multiple columns? (Excel example included

    Hi!

    I have a gantt chart I created that basically visualizes a schedule of car repairs, it is here:

    ufile.io/0wjiy

    The feeder sheet is by customer by day, and then the main sheet just takes that info and puts it by Bay. The Main sheet has lookups that print out the customer name for each bay, it's designed this way so conditional formatting can be used to color the name of each customer.

    This works fine but I want I would like is above each colored line (Bay) on the Main Sheet, I would like an automatic description of each customer's work.

    But I can't do that using formulas because the columns are so tiny that you wouldn't be able to read anything because each column would have a formula and Excel doesn't let any adjacent text overwrite anything in a formula even if the result of the formula is blank or 0.

    Look at my comment for an example of how I would like for it to look.

    So, I think I need some kind of macro that somehow knows when the cell directly below (in the same column) changes from customer A to customer B (and if there is no customer there there should be no description).

    This doesn't seem like it would too hard since:

    1.) The rows that I want descriptors on (rows 12,15,18,21,24,27,30,33,36,39) will not change

    2.) The lookups on the Main Sheet are set up to give the name of the customer from column F on the feeder sheet. This means that the descriptor row can tell when to print out a descriptor by just printing it out when the cells in the row above switch customer names or go from customer name to 0.

    3.) The customers will NOT change often on the same row (if there is a change it is at least a month wide). Although I do see a couple times in Bay 9 and Bay 10 where it is only a few days long, ideally the macro would only print a description if there are something like 20 days in a row where there is a non zero value in the cell.

    Anyway, is this possible at all?

    This may not be the best idea but my idea would be for the macro to use if statements based on the cell below, and if the cells based the check then they would print the result of the formula that I have written in each BAY 1 INFO cell line. Importantly, if it doesn't pass the test then the cells will be completely blank with no formula so the text can continue on.

    Any ideas?

    Thanks for reading!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Looks like a sheet_change event should work. Can you:

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Thanks for the reply! I have uploaded it via your method, but I had to delete a lot of rows of sample data (nothing important) you should still be able to see what I'm talking about. I'm not sure if a before/after version would help, to see what I want look at rows 12,15,18,21,24,27,30,33,36 of the 'Main Sheet'. There is one cell with a comment that kind of shows what it would look like if text could overwrite adjacent cells.

    One thing that got lost since I had to delete info to upload this way was that I had Bay 9 and 10 having some work that lasted only a week in a few places. I mention that in case there is a way to do what I said above where the macro would only print the formula in the cell if the cells below repeat the same result for X number of days.
    Attached Files Attached Files
    Last edited by Katie620; 06-29-2017 at 05:07 PM.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    I'm not feeling very bright, that is, I'm not sure exactly what it is that you want

  5. #5
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76
    Quote Originally Posted by xladept View Post
    I'm not feeling very bright, that is, I'm not sure exactly what it is that you want

    Ok, im sorry

    Ill write a better description tommorow but is a particular part that is unclear? Is it the concept of wgat the file does now, or more about what i want the macro to do?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    What you want the macro to do and what is the data.

  7. #7
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    ok

    Unless you can think of an easier way this is what I want the macro to do:

    1.) Run the macro on specific rows (12,20,28,36,44,52,60,68,76,94 is what I currently need but I know that doesn't match what I have attached. It's just every row one row above where each block of schedule/bay is) beginning at column E. An ending column isn't necessary but if it must be specified, column NG is the last column.

    2.) For every cell on these rows within that range:

    * If the cell one row down on the same column is blank (FYI it is not technically blank it is made blank by a formula) OR if the cell one row down on the same column equals the cell one row down and one column to the LEFT, then clear that cell.
    *If not, then:

    Make the cell have this formula:

    =IFERROR(INDEX('By Line'!$C$4:$C$236,MATCH($B12&TRUE,'By Line'!$B$4:$B$236&'By Line'!Q$4:Q$236,0)),0)

    Where $B$12 must change so that the '12' will always equal whatever row number the macro is looking at at the time. So if its run on row 20, the formula will change to $B$20.

    I think my logic there is ok, essentially I want it only print the formula when the cell below changes to a non zero new value. And again, all of this is so that I can have text display over multiple columns automatically.

    One final note: if possible, I would like it to do a check before it prints out the formula. The check would be: only print out formula if the cell one row down on the same column has the same value for the next 20 columns. If not, do not print out the formula AKA make it blank. (Sometimes I have some blocks of time that only last a week or so, and I don't want to have a description above those)


    Does that make sense? I'm not sure what other data to give you other than what I already attached.

    Thank you for reading!! Please let me know if you have further questions or if I can help in any way!
    Last edited by Katie620; 06-30-2017 at 11:25 AM.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Hi Katie,

    It looked like a scary chore with those array formulas - so, this guru is trying a "better way"

    Let me know a few things that are wrong for this first attempt:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Thanks for that!! That didn't work for me I was trying to figure it out, but I had an idea!!!!

    Instead of worrying about the macro trying to input a formula, I created new rows and put those formulas in those rows. So now all the macro has to do is grab what is in the row above.

    Please see my revised file. So each bay on the "main sheet" has three rows:

    1.) Top row: this is the formula that will get the description for each block.

    2.) Middle row: This is where the macro will run. I've made some static entries to show you how I want it to look. Note how the two shorter time frames are under 20 days so they have no description (Bay 4 and Bay 7).

    3.) Bottom row: This wasn't changed still just the schedule based on the "feeder sheet" tab.

    So does that make it more clear and perhaps make the macro easier?

    I don't think the macro logic will change that I gave earlier. Just, instead of imputing a formula it just has to grab the result of the formula in the row directly above each cell.

    Thank you for your help so far!! Please let me know if you have questions!
    Attached Files Attached Files

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Katie, what is the main sheet supposed to look like? The macro seems to be duplicating what's there

  11. #11
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Ahh that's partly right, the macro does duplicate what's there. The reason is because the results of the formula on the top row of each bay can't be displayed because each cell is a formula, and excel doesn't let text from one cell go over another cell if the other cell has a formula in it even if the result of that formula is zero. Do you know what I mean? If you look at the top row of each bay where the formula is you can't see anything because the columns have to be very thin and because each cell in the row has to have the formula.

    So if you look at my latest attachment from earlier today, that is what I want it to look like (the middle row has static text that I put it to show what I want it to look like). But just using formulas that isn't possible so I need a macro.

    Does that makes sense? thanks for the reply by the way!

  12. #12
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Is this just impossible to do with a macro ? I'm trying to piece together parts of it using the code from the macro recorder but the if statements are driving me crazy.

  13. #13
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Hi xladept,

    Maybe I should just make a new thread because I wasn't exactly sure how to explain what I wanted when I made this one. Here is a (hopefully) concise recap of what I'm trying to accomplish:

    I'm trying to write a macro that uses IF statements to solve the problem where text can't overflow into adjacent columns if there is a formula in the next columns. So I'm just trying to have a description above each block of time, I can't use formulas for this because of the reason I just mentioned.

    I'm trying to make this car repair schedule:

    First image below


    Look like this:

    Second image below


    The example excel file is attached.

    The yellow cells in column B are the rows where I need a macro. But note that I have made everything static, there are supposed to be formulas in the other two lines (rows 13 and 15, rows 23 and 25, etc).

    I'm trying to have above each colored block of time, a description of the work below, as long as the block is 30 or more days long. The description (where the macro will pull the data from) is simply in the cell above, and the block of time is in the cell below, with the macro line in between both.

    I think the logic I need is:

    Run the macro on specific rows (14,24,34,44,54,64,74,84,94,114) beginning at column F. An ending column isn't necessary but if it must be specified, column NG is the last column.

    For every cell on these rows within that range:

    If the cell one row down on the same column is blank (FYI it is not technically blank but is made blank by a formula) OR if the cell one row down on the same column equals the cell one row down and one column to the LEFT, then clear that cell.

    If not, then:


    Make the cell equal the cell directly above (which will have the description).

    One last condition: The cell should only equal the cell directly above if the block of time below repeats for 30 or more days (which are the same as columns in my spreadsheet). If you look at my images this just makes it so that a description doesn't appear above the block of time if the block of time is too short to really show anything.




    I think the above will give me what I have in my second image. Does that make sense? I've tried writing this using some if statements I've found on the internet and using the macro recorder for the other parts but I can't get close to anything workable.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Katie620; 07-05-2017 at 02:14 PM.

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    The before sheet has no information on it?

  15. #15
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    I'm not sure what you mean exactly? The before sheet is the same as the after sheet except that the after sheet has the descriptions above the colored sections. The before sheet is what should be used to write the macro, the after sheet is what the before sheet should look like after the macro has been run on it.

    If you mean in comparison to the files I previously uploaded in this thread, what I did was just strip out all of the formulas and made everything static. I did it to make it more clear, it shouldn't affect the macro.
    Last edited by Katie620; 07-05-2017 at 02:59 PM.

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Hi Katie,

    I saw all that - but, my first attempt was in the interest of a "better way" - but you just want to use formulas; correct?

    Are they actually formulas or just text?

  17. #17
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Ahh man, I'm confused as well now I don't completely understand the code you posted or what you mean by better way, which is why I don't understand what you're getting at.


    I am still using the long index match formulas, but I have made those lines static in my new example. But I'm not sure it matters whether they are static or not? If you have a cell equal another cell using a macro, does it matter if that cell is a formula or static? I mean the macro will look at those two lines above and below the lines the macro is run on for two reasons:

    1.) The macro will make a cell to be equal to the cell above it follows certain conditions.

    2.) The macro will compare the cell below to the previous cell on the same row to see if they are equal to each other.

    Does it matter if those cells are static or formulas?
    Last edited by Katie620; 07-05-2017 at 03:45 PM.

  18. #18
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    I might be as confused as everyone else, but see if my effort below contributes (positively) to progress. I used your original sample and created a worksheet activate event. Every time you switch to the Master Sheet, it will look in column B for entries that match column B on your Feeder sheet, thereby identifying the Bays. In the row above each Bay, it should insert the description in the cell that aligns with the start date, but only if the date duration is longer than 20 days. That was my interpretation of the request; hopefully I'm close? Tying the changes to the dates on the feeder sheet made more sense to me than designing them around the formulas used for the bars on the Master sheet. I toyed with some of your sample data and it appeared to hold up. Take a look at the attachment to see if it works as desired:

    Please Login or Register  to view this content.
    EDIT: It'll need some modifying if it's going to apply to multiple blocks on the same bay. How will Bays with multiple start/end dates appear on your Feeder sheet?
    Attached Files Attached Files
    Last edited by CAntosh; 07-06-2017 at 10:56 AM.
    If your problem has been solved, please use "Thread Tools" to mark the thread as "Solved".

    If you're grateful for this site's existence and would like to contribute to the community, please consider posting something hilarious in our joke thread:
    https://www.excelforum.com/the-water...ke-thread.html

  19. #19
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Here's an alternative that I think will work with multiple entries in the same bay. This one is based off of the data on the main sheet. Wherever it sees the start of a stretch of 20 or more days with values greater than 1 on a bay row of the main sheet, it implants the description from the feeder sheet above the first entry. It will be triggered whenever the main sheet is activated. It's not tremendously efficient, so if you have tons of bays, this version may take a few seconds to update, but with only 9 bays it's nearly instantaneous. It seems to be testing cleanly for me, but take a look at the attachment to see if it'll do.

    N.B.: In the attachment, I changed some of your formulas on the bay rows of the main sheet into values so I could more easily test the functionality of the procedure. The procedure works fine on both values and formula-generated results, but I didn't want to guess as to how you applied multiple blocks to your chart.

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    06-29-2017
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    76

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    CAntosh thank you so much! This is a great start that I can build off of. You're right, the big issue here is when there are multiple blocks on the same bay.

    Check out this sample attached (I hate that it's different that what you are working with, but I thought I would change it to more reflect my real data/formatting, it is also attached a few posts ago so hopefully this isn't totally out of the blue)

    These two sheets reflect the 'main sheet' in the file you're working with. You can see I added rows above the 'INFO' rows for each bay. These rows are static in this sample, but in the real file they use index matching to pull the exact description from the feeder sheet that matches the bay in that time frame, so all the macro has to do is look up to pull the description where applicable.

    I'm going to try to work off your sample as a framework to see if I can get it working on this other version. Again, thank you so much for that!
    Attached Files Attached Files

  21. #21
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    My second effort should adapt pretty cleanly to the new sample. I changed the name of the "After Macro" sheet to "Master Sheet" and went with the following:

    Please Login or Register  to view this content.
    It still triggers each time you activate the sheet. Try the attachment to see if it works.

    EDIT: It should be noted that changing the name was meaningless. Just habit. As long as the event is applied to the correct sheet, the sheet name is meaningless.
    Last edited by CAntosh; 07-06-2017 at 01:24 PM.

  22. #22
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,844

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    It's not easy to understand what you mean but I needed some Excel time so I just made something.

    I like arrayformulas but here they were just slowing things down while doing mostly nothing so I went for VBA.
    Attached Files Attached Files
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  23. #23
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,844

    Re: Need a macro that allows me to place text across multiple columns? (Excel example incl

    Forgot to mention, it ads the text you want but when there is not enough room it ads it in a comment instead.

+ 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] Place text from multiple columns into one cell based on another columns value
    By minesht in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-05-2015, 05:44 PM
  2. Replies: 3
    Last Post: 12-16-2013, 05:16 AM
  3. Search for text in multiple columns with same heading - excel Macro
    By anytimesampath in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2013, 08:26 AM
  4. Compare 2 columns near equiv (one has text included) and output to new column
    By CNE5x in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2012, 01:24 PM
  5. Macro to increment column and copy columns to next row (check box included)
    By mani_v23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2009, 12:54 PM
  6. Dates out of place (file included) **second attempt**
    By Kostanzas200 in forum Excel General
    Replies: 4
    Last Post: 01-24-2008, 08:06 PM
  7. Dates out of place (file included)
    By Kostanzas200 in forum Excel General
    Replies: 1
    Last Post: 01-24-2008, 05:30 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