+ Reply to Thread
Results 1 to 8 of 8

How to indent all strings that are not in all caps in the worksheet?

  1. #1
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    How to indent all strings that are not in all caps in the worksheet?

    I have alternating columns of strings and numbers, with an empty column after every 2 columns, like this:

    PROPERTY A PROPERTY B
    REVENUE REVENUE
    Item1 25,000 Item 1 5,000
    Item 2 10,000 TOTAL REVENUE 5,000
    TOTAL REVENUE 35,000

    What I would like to do is indent all the strings that are not in call caps. So for the example above it would indent everything with the word "Item"

    In Excel I know how to do a function that tests to see if it's all caps:

    =IF(EXACT(K14,UPPER(K14)),"Do nothing","Indent")

    However, I don't know how to do this in VBA and how to make it apply to all strings on the particular sheet. Any help would be greatly appreciated

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to indent all strings that are not in all caps in the worksheet?

    You could use this macro, which will indent any cell that contains a lower case letter. Formulas that return a non-all upper case result will be replaced with a constant, the (indented) value.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    Re: How to indent all strings that are not in all caps in the worksheet?

    Caps Indent Example.xlsm

    I'm a little confused by the code. I tried with the real data and it ran, but didn't indent. I've uploaded a sample.

    I'm not sure what you meant by "Formulas that return a non-all upper case result will be replaced with a constant, the (indented) value."

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to indent all strings that are not in all caps in the worksheet?

    In the file you attached, all the cells with a lower case letter already have an indent (vbTab = CHAR(9)). If you want a different index character, you can change that in the indicated line in the code.
    Also, a spurious line got inserted into the code. You should copy paste the code again.

    If you have a formula in a cell like ="aB" & A1, and A1 holds "C" the routine will replace that formula with an indented "aBC". But as a constant, so that changing the value of A1 will not change the cell value.

  5. #5
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    Re: How to indent all strings that are not in all caps in the worksheet?

    I'm lost here. In the second example I made a mistake and had 1 line indented "office rent" in the 1st column. I don't see anything else on the sheet indented. May the problem is I don't understand how indenting works with VBA. What do you mean by (vbTab = CHAR(9))? I tried looking it up and "CHAR" has something to do with ASCII.

    When I record indenting by changing the alignment it uses "Selection.InsertIndent 1"

    There are no formulas in the strings I want to indent

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to indent all strings that are not in all caps in the worksheet?

    Another way:

    Please Login or Register  to view this content.
    Last edited by shg; 07-14-2014 at 03:56 PM.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to indent all strings that are not in all caps in the worksheet?

    Thanks shg, I didn't know about the IndentLevel property.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to indent all strings that are not in all caps in the worksheet?

    Curiously, InsertIndent is one of those methods that works in a UDF; I use it to indent work breakdown structures.

    Please Login or Register  to view this content.

+ 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. Indent move cell, 2 indent move 2 cells etc
    By jomuir in forum Excel General
    Replies: 3
    Last Post: 05-14-2012, 11:56 AM
  2. How can I convert all Caps to first letter caps in Excel?
    By Fenljp26 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. How can I convert all Caps to first letter caps in Excel?
    By in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 07:05 AM
  4. How can I convert all Caps to first letter caps in Excel?
    By Fenljp26 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. [SOLVED] excel sheet all caps and needs to be only the first letter caps..
    By kroberts in forum Excel General
    Replies: 1
    Last Post: 03-07-2005, 11:06 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