+ Reply to Thread
Results 1 to 12 of 12

Auto align depending on certain text

  1. #1
    Registered User
    Join Date
    01-15-2019
    Location
    uk
    MS-Off Ver
    Microsoft 365
    Posts
    21

    Auto align depending on certain text

    Hi

    I am working on a spreadsheet where I select a option from a dropdown list and I am hoping to find a way for certain words to auto align on the right rather than the left.
    I have had a play but cannot find a way to get this working.

    In the attached spreadsheet I would like the options Part, Scrap and Packaging to align on the right, all other selections I would like to keep aligning on the left.

    Over time I would like to be able to add words to the dropdown list and select which ones I want on the left and which on the right.

    If anyone can help I would be very grateful.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Auto align depending on certain text

    Does this work for you?

    In the code for the Alignment sheet.

    It copies the alignment from the list used in the data validation.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-15-2019
    Location
    uk
    MS-Off Ver
    Microsoft 365
    Posts
    21

    Re: Auto align depending on certain text

    Thank you for the reply.
    It works really well on that spreadsheet.

    I have a couple of other spreadsheets that I would like to also use it on, but I cannot seem to get it to work.
    I have put the same code into each of the other pages I want it to work on but the alignment does not work, although when I delete the text in the cell I get the following error message:

    Run-Time error '13':

    Type Mismatch

    Is there something I need to change in the code for each spreadsheet?

    Thank you

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Auto align depending on certain text

    Please try:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-15-2019
    Location
    uk
    MS-Off Ver
    Microsoft 365
    Posts
    21

    Re: Auto align depending on certain text

    Thanks, this appears to have stopped the error message when clearing a cell but it is still not changing the alignment.

    This is my first time using code so just want to make sure I am doing it right (guessing I am as it is working in the original sheet).

    I am right clicking the tab and selecting "View code", then I am just pasting the text into the blank worksheet.

    I have also tried inserting a "Module" and pasting it in there.

    Thank you for your help

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Auto align depending on certain text

    right clicking the tab and selecting "View code", then I am just pasting the text into the blank worksheet.
    Yes, in the sheet where the cells have data validation applied.

    I have also tried inserting a "Module" and pasting it in there.
    As a change event, this need to be in the worksheet that's being changed, not a module.

  7. #7
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Auto align depending on certain text

    If you're applying it to multiple sheets, rather than repeating this code in every sheet you can place this in the ThisWorkbook code.
    Delete the code from the individual worksheets.


    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-15-2019
    Location
    uk
    MS-Off Ver
    Microsoft 365
    Posts
    21

    Re: Auto align depending on certain text

    I have removed the code in the individual sheet and deleted the module and inputted this code into the worksheet.

    Unfortunately the alignment is still not working, I will keep playing around though.

    Thanks

  9. #9
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Auto align depending on certain text

    This works for me.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-15-2019
    Location
    uk
    MS-Off Ver
    Microsoft 365
    Posts
    21

    Re: Auto align depending on certain text

    Yeah I have got it working nicely in that workbook, but I cannot seem to get it working in my other workbooks (I have a few that differ slightly depending who they go to).
    That's why I am so stumped as I can get it working on one workbook.
    I am starting to go through the settings to see if something is stopping the code from activating.

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Auto align depending on certain text

    Can you post the non-working one?

  12. #12
    Registered User
    Join Date
    01-15-2019
    Location
    uk
    MS-Off Ver
    Microsoft 365
    Posts
    21

    Re: Auto align depending on certain text

    Unfortunately as they are work files I am prohibited from sharing externally.

+ 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: 3
    Last Post: 01-20-2022, 10:21 AM
  2. [SOLVED] Auto Convert Cell Format to Text Depending on Another Cell
    By AlPragOrg in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-26-2021, 05:37 PM
  3. VBA excel to word insert footer (Text - Left align) & (Page number - Right align)
    By Richavlaues in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2017, 06:22 PM
  4. A macro to auto fill in text depending upon cell content
    By johngefc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2014, 01:03 PM
  5. Auto Align column A with C
    By mandukes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2014, 02:12 AM
  6. [SOLVED] VBA to auto merge and middle align for particular row in dynamic range
    By cruise.alter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2012, 02:32 AM
  7. auto align
    By kersleykim in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2007, 04:31 AM

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