+ Reply to Thread
Results 1 to 4 of 4

Automatically conditionally format font size based on text length

  1. #1
    Registered User
    Join Date
    09-09-2012
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    5

    Automatically conditionally format font size based on text length

    Greetings

    I have a staff rota spreadsheet which shows D for rostered days N for nightshift H for holiday and various other abbreviations and I want the cell to automatically change font size for the following conditions:
    text length <=2 I want font size to be 11
    text length = 3 I want the font size to be 10 and
    text length >3 I want the font size to be 5

    Being a VBA 'feartie' (I am trying here but its so difficult,dont get me wrong I just love wasting the time messing with VBA but I GIVE UP on this one :-( ) I wonder if anyone might be able to help. I've googled for some ready made code for this and found similar solutions that I have tried to adapt with zero success. What I have learned is:

    I need a 'ByVal Target is Range' statement
    I need to declare and dimension a variable as a range object which I have called 'cr'
    I think a case statement will do the trick.

    I've got as far as:

    Please Login or Register  to view this content.
    Which doesn't create any vba error messages, HOWEVER, when I run the code ... Dan Dan Daaaaaannnnnn!!!!! .... NOTHING Happens

    All help, advice, suggestions very gratefully received.

    TIA

    Rob
    Last edited by JBeaucaire; 09-09-2012 at 06:39 PM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Automatically conditionally format font size based on text length

    Something like this:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-09-2012
    Location
    Swindon UK
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Automatically conditionally format font size based on text length

    Thank you so much! I've been struggling with this for days now and finally at last I can move on with it. So simple!! I understand all the code except the 'If Not Intersect (Target, Range...' code up to the case statement, but thats where the really interesting fun starts for me - figuring out what it actually means - great fun :-)

    You have made my night!

    Cheers

    Rob

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Automatically conditionally format font size based on text length

    In simple terms it checks to make sure there WAS a change in column B. If there wasn't a change in column B, nothing happens. If there was, it cycles through all the cells that were changed in column B (that's the intersect) one at a time and runs your font code on them.

    If that takes care of your posted question, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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