+ Reply to Thread
Results 1 to 10 of 10

Cell Formatting

  1. #1
    Registered User
    Join Date
    11-03-2015
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    13

    Cell Formatting

    Hello all,

    I have cells with 2 data types in them; date and text.
    The date is the first 5 characters of the cell as a serial number and then the following is alt enters and text.
    Is there a way to format this cell to show the serial number as day and the remaining text as text?
    Bear in mind that I refer to these cells to obtain the serial number for other formatting.

    Thanks in advance,

    Matt

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Cell Formatting

    No - you either have a date (the serial number which can be formatted differently) or text, but you cannot have both in one cell.

    You can have two cells, one with a date (A1), and the other with text (a2), and a third with a formula like this to combine them into one string

    =TEXT(A1,"mmmm d, yyyy ") & A2
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Cell Formatting

    See the attached file. Just click on the cell containing data and run the dural macro:
    Attached Files Attached Files
    Gary's Student

  4. #4
    Registered User
    Join Date
    11-03-2015
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    13

    Re: Cell Formatting

    Ok, this is definitely a step in the right direction as to what I was looking for, so thanks for that!

    The output is not using the same alt enters to place the data on the same lines as before, basically eliminating them. Also it doesn't seem to go through the whole cells data because if you add another alt enter and line of text it gets left out of the format. I added an ActiveCell.ClearFormats at the beginning of this macro so that it could be reran for testing but that wipes all other formats that have been applied so it would be good to have it clear this format first then go through to apply it, that way it could be reran on pages where I will be updating info.

    Thanks for any further help,

    Matt

  5. #5
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Cell Formatting

    Here is a slightly improved version:
    • it will loop through all the cells you select
    • it clears the format
    • it uses the ascii 10
    • it retains the text wrapping
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-03-2015
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    13

    Re: Cell Formatting

    Aweosme progress!

    The only thing still not working is the multiple lines of text after "Hello World" which I have had to add to validate and confirm they are indeed being dropped likely from the way the array is grabbing the cell data. Would MID grab the first 5 and then MID to LAST grab the rest properly?

    I know just enough to be dangerous

  7. #7
    Registered User
    Join Date
    11-03-2015
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    13

    Re: Cell Formatting

    OK, so I finally am wrapping my head around how your code is working, so if I add another & Chr(10) & ary(2) to the end of s3 AND there is an extra line it will then add that data to the output, but again leave off any other lines. I think I need a statement to count the ary()'s and add the extra statements as needed through a loop or case statement.

    Thanks again!

  8. #8
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Cell Formatting

    Here is a fix to the multiple line of text:
    Attached Files Attached Files

  9. #9
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Cell Formatting

    I would advise you not to have the serial number combined with text if you are going to use the serial number with other calculations. All you are accomplishing is to complicate matters. Keep the data types separated and you will have a much easier time of it even though what you want is feasible...it may turn out not to be practical.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  10. #10
    Registered User
    Join Date
    11-03-2015
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    13

    Re: Cell Formatting

    Wow, Brilliant

    Join() much better solution than I could have come up with lol

    Thanks again for all your help!

+ 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: 11-04-2013, 12:47 AM
  2. Replies: 1
    Last Post: 08-28-2013, 09:07 AM
  3. Replies: 1
    Last Post: 07-02-2013, 07:57 AM
  4. Conditional Formatting via VBA: Change formatting in range based on value of each cell
    By ralphjmedia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2013, 10:37 AM
  5. Delete Conditional Formatting conditions but keep cell formatting - Excel 2010
    By tetreama in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 08:28 PM
  6. Replies: 1
    Last Post: 03-05-2012, 06:20 PM
  7. Replies: 2
    Last Post: 11-02-2007, 12:03 PM
  8. Replies: 4
    Last Post: 07-18-2007, 05:39 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