+ Reply to Thread
Results 1 to 13 of 13

Conditional Formatting, Indent Text in Cell

  1. #1
    Registered User
    Join Date
    02-28-2013
    Location
    North Pole
    MS-Off Ver
    Excel 2010
    Posts
    6

    Conditional Formatting, Indent Text in Cell

    I want to format a cell such that if it contains certain text then it is indented. For instance I have a step number and a sub step. The sub-step has a '.' in it. Example 'Fuel_3' is the Step # and 'Fuel_3.1' is the sub-step. Under conditional formatting there isn't an alignment option.

    Thanks for your help.
    Last edited by iyoung2001; 03-05-2013 at 01:46 PM.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Conditional Formatting, Indent Text in Cell

    You'll need to use VBA. Assuming that the steps will go into column A, I wrote this code
    Please Login or Register  to view this content.
    See attachment
    Would that work for you?
    Attached Files Attached Files
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Conditional Formatting, Indent Text in Cell

    Ahh, see that the . isn't at the beginning of the string.

    Revised code
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-28-2013
    Location
    North Pole
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Conditional Formatting, Indent Text in Cell

    Thanks for the quick response. This looks close, but I'm getting an error on the If Intersect Line "Error '424' Object Required".

    Any thoughts?

    I wish I was more fluent in VBA.

  5. #5
    Registered User
    Join Date
    02-28-2013
    Location
    North Pole
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Conditional Formatting, Indent Text in Cell

    Sorry I had posted that I was able to make progress, but I'm still having the previous problem.
    Last edited by iyoung2001; 03-05-2013 at 12:07 AM.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Conditional Formatting, Indent Text in Cell

    Do you have that problem with my spreadsheet or when you try to put it into your sheet (or both)?

  7. #7
    Registered User
    Join Date
    02-28-2013
    Location
    North Pole
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Conditional Formatting, Indent Text in Cell

    Making progress. I figured out I was putting your code in the wrong place. I had it in the module instead of sheet1 code. So now it behaves the same in both sheets. I get an error "Run-time error '1004': Unable to get the Search property of the Worksheet Function class" when I enter a cell that doesn't have a "." But it does work correctly when there is a "." in the text.

    Also one thing I failed to mention would be to also indent Column C if Column A is indented. Hopefully that doesn't add too much complexity.

    Thanks again for your help, this will save me a ton of time.

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Conditional Formatting, Indent Text in Cell

    The error handler should take care of the issue with not finding a "." Hmmm
    In any case, to get Col C to indent also (Note, if you don't want it to indent so far, change "Indent 3" to "Indent 2" or "Indent 1"
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-28-2013
    Location
    North Pole
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Conditional Formatting, Indent Text in Cell

    I started over from scratch on a new worksheet and now it works great.

    I was playing around with the code you gave me and quite possibly screwed something up. (Commented that section out or something). Either way I'm sure it was user error.

    Again lots of thanks for your help.

  10. #10
    Registered User
    Join Date
    02-28-2013
    Location
    North Pole
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Conditional Formatting, Indent Text in Cell

    OK I marked this as solved, but I have one last question. Is it possible to put this code in a module instead of a Sheet Code? If I copy your code into a module, remove the private, and add a name it's not showing up in the macro list to run.

    To explain how I'm using this a little more. I'm exporting from a website, so I need to be able to apply the indent after the data is already in the sheet, not as I'm typing it in. So basically a macro I can run on any sheet that already has data in it.

  11. #11
    Registered User
    Join Date
    05-10-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Conditional Formatting, Indent Text in Cell

    Just for kicks and giggles, there's actually a non-VBA way to accomplish this too. The secret is to create a "add spaces to the beginning of the cell" number format.

    In this case, since your condition is to identify cells that have a ".", use the SEARCH function in your Format Rule. Since SEARCH returns an error if it doesn't find the string, you would be looking for cells that don't return an error when searching for "."

    So, your Format Rule would be for example: =NOT(ISERROR(SEARCH(".",A1)))

    When you meet the condition, use this Custom Number Format: " "@ (use the number of spaces between the quotes to your preference)

    I use this to represent Master offices and their sub-office locations nested beneath and it works beautifully.

  12. #12
    Registered User
    Join Date
    02-14-2020
    Location
    UAE
    MS-Off Ver
    365
    Posts
    1

    Re: Conditional Formatting, Indent Text in Cell

    thanks for sharing. i was looking for this.

    if i want to indent cells contains numbers using the condiitional formart. how to acheive that?

  13. #13
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.95 for Mac MS 365
    Posts
    8,690

    Re: Conditional Formatting, Indent Text in Cell

    welcome to the forum proangel, please check the forum rules (link at the top of the post and on the main pages) particularly rule #4 about posting for help on an existing thread.
    If you have an issue you need help with please start your own post (they are free ) and if you think this post is relevant then copy the link and paste it in your own post.
    that way people can give you answers specific to your needs. Oh also post a sample workbook if that will help show your issue.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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