+ Reply to Thread
Results 1 to 19 of 19

Formatting a cell with an if function and a formula

  1. #1
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Formatting a cell with an if function and a formula

    Hi,

    I've been trying to find out if its possible to format a cell to 'if the word 'ASAP' is entered into that cell then it displays the current time at which the text was entered'.

    Example
    If in cell A1 i enter the text 'asap' then cell A1 should display the time at which the word 'asap' was entered into cell A1.

    Thanks in advance
    Suban

  2. #2
    Forum Expert boopathiraja's Avatar
    Join Date
    07-12-2013
    Location
    Coimbatore,TamilNadu, India
    MS-Off Ver
    Excel 2007, 2013, 2016, 365
    Posts
    1,455

    Re: Formatting a cell with an if function and a formula

    May be in B1

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Click just below left if it helps, Boo?ath?

  3. #3
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Thanks for the reply, but wouldn't that condition cell B1 based on cell A1s content?

    I was wondering if it were possible to use formulas or functions to do this without using another cell.

  4. #4
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Hi, is anyone else able to help with this please?

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Formatting a cell with an if function and a formula

    Pl see attached file.Worksheet_Change event is used.
    Range used is A1:A3, can be changed in the code.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Thank you. that works well. is there a way to do this without using vba code and just using the functions of the excel?

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

    Re: Formatting a cell with an if function and a formula

    No, there is no way to do this without VBA. Conditional formatting only covers number formatting, font formatting and cell coloring and borders. You cannot, without VBA, enter ASAP manually and have a date pop up in the same cell.
    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

  8. #8
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Okno worries. thanks for your help guys

  9. #9
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Hi all, so the vba written by kvsrinivasamurthy in the attachment above works well, however, when i try to delete the data entered in 2 or more cells i get a 'run-time error' 13': type mismatch. Could anyone help me with this error please?


    Sent from my iPhone using Tapatalk

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formatting a cell with an if function and a formula

    You can have the date or time entered in another cell.

    See this for some techniques.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  11. #11
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    hi tony,

    i don't quite understand your reply.

    i'm trying to achieve a way of time stamping when the word asap is written in a cell. kvsrinivas has kindly sent me the vba code which is contained within the spreadsheet attached above, but the issue i have is after typing asap into 2 cells and then i highlight both cells and delete, i get a 'run-time error' 13': type mismatch.

  12. #12
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    hi,

    thanks. this worked really well, but has one issue. after typing 'asap' into 2 cells and then i highlight both cells and delete, i get a 'run-time error' 13': type mismatch. anyway you could help?

    Thanks
    Suban

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formatting a cell with an if function and a formula

    The link I provided shows different ways to use date/time stamps.

  14. #14
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Ok thanks.


    Sent from my iPhone using Tapatalk

  15. #15
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Hi is anyone else able to help directly with the code?

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A1:A3")) Is Nothing Then

    Application.EnableEvents = False

    If UCase(Target.Value) = "ASAP" Then

    Target.Value = Time

    End If

    Application.EnableEvents = True

    End If

    End Sub

    Thanks in advance
    Suban


    Sent from my iPhone using Tapatalk

  16. #16
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Formatting a cell with an if function and a formula

    Adding Target.Count = 1 means that the code will only be triggered when one cell is being changed ... not when you are clearing many cells at once.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Thank you so much nimrod. If you have the time and you don't mind could you explain what your piece of code does.

    Thanks


    Sent from my iPhone using Tapatalk

  18. #18
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Formatting a cell with an if function and a formula

    Hello suban:

    I added "Target.Count = 1" to the code. What this does is assure that your code for testing for the value "asap" only happens when you are only changing one cell (i.e. target count = 1). This way wwhen you are clearing many cells i.e. target.count > 1 , then you don't run your "asap" code ... which will blow-up when more then one cell is the target. Does that make sense ??

  19. #19
    Registered User
    Join Date
    10-08-2014
    Location
    UK
    MS-Off Ver
    2013
    Posts
    19

    Re: Formatting a cell with an if function and a formula

    Ahhh i see. Yes that makes sense. Thanks again nimrod


    Sent from my iPhone using Tapatalk

+ 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. Function, Formula, or Conditional Formatting
    By long8484 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-30-2014, 03:45 PM
  2. Use of cell formatting in a function
    By prairiestone in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-22-2014, 06:13 PM
  3. [SOLVED] Using a formula that contains the indirect function for conditional formatting
    By Teekith in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-15-2013, 09:45 AM
  4. Formatting a Cell within a function
    By Neil07979 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2008, 08:57 AM
  5. [SOLVED] Formatting a cell with a function (IF statement)
    By Biff in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM

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