+ Reply to Thread
Results 1 to 10 of 10

Change cell number format using IF

  1. #1
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    272

    Change cell number format using IF

    Is there a way to format a cell based on the value of another cell? If it were an IF statement it would be (in B1) =IF(A1="Sales","Currency format","Number format, decimal=0").
    Any help would be greatly appreciated!
    Sick
    Last edited by sick stigma; 12-27-2019 at 05:16 PM.

  2. #2
    Registered User
    Join Date
    10-23-2019
    Location
    Baku,Azerbaijan
    MS-Off Ver
    Win 10
    Posts
    1

    Re: Change cell number format using IF

    Hi,
    Please try this one:

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 12-27-2019 at 04:50 PM. Reason: Please use code tags!

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Change cell number format using IF

    Hi Sick,

    How about?

    Please Login or Register  to view this content.
    Paste code in a Sheet module
    • Where to paste code
    • Highlight macro to copy >> Ctrl + C >> Open your workbook
    • Right click on sheet tab >> View Code >> opens the Visual Basic Editor (VBE)
    • Ctrl + R >> opens the Project Explorer (if not already open on left side of screen)
    • Paste code >> Ctrl + V (right side of screen)
    • Alt + Q >> exits VBE and returns to Excel
    • Now simply make a change in target cell
    HTH
    Regards, Jeff

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Change cell number format using IF

    Do you really need to do this with macro? (then probably indeed with event handler as shown above).
    But remember, that you could use simple conditional formatting for that.

    see the attached file (it's recycled from other thread).
    I selected the C2:C13 range and used conditional formatting with format based on formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and formatting as currency EUR
    Standard format for these cells was number with no decimals
    Attached Files Attached Files
    Best Regards,

    Kaper

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Change cell number format using IF

    Yes, thanks Kaper. That completely slipped my mind.

  6. #6
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    272

    Re: Change cell number format using IF

    Jeff,
    How does it know which cell to change (B1)?

  7. #7
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    272

    Re: Change cell number format using IF

    Kaper wins!!!!!!
    TYVM!
    Sick

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Change cell number format using IF

    Hi sick,

    I guess you are referring to the Change Event in post #3? If even see I made a typo.

    This
    Please Login or Register  to view this content.
    Should be
    Please Login or Register  to view this content.
    So the target is anything in Column A. Once you make a change to anything in that column, we then offset one column to the right which would be column B.

    Please Login or Register  to view this content.
    This is saying, act upon the target (anything in column A) and then offset no rows (0), but one (1) column right.

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Change cell number format using IF

    Quote Originally Posted by sick stigma View Post
    Kaper wins!!!!!!
    TYVM!
    Sick
    Glad this worked out for you. Thanks for the feedback.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Change cell number format using IF

    Thanks for marking the thread SOLVED and for reputation point.
    If you haven't done so, you could also give reputation to those who answered with VBA suggestions (you posted it on Excel Programming / VBA / Macros sub-forum, so most answers were employing VBA).
    As opposite to many other forums on excelforum you could grant reputation to many helpers. Moreover, you could do it even in threads not started by you, which were especially useful.

+ 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. [SOLVED] Change cell number format using IF
    By sick stigma in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-27-2019, 04:30 PM
  2. Show Error when a cell with number format change to date format
    By delroba in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-08-2015, 02:57 AM
  3. Dynamically change number format of a cell
    By stevelo in forum Excel General
    Replies: 16
    Last Post: 08-21-2013, 10:52 AM
  4. cannot change cell format from Text to Number
    By rpait in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 04-14-2013, 07:06 AM
  5. How do I dynamically change the Number Format of a cell
    By johnw993 in forum Excel General
    Replies: 2
    Last Post: 01-14-2013, 05:02 PM
  6. Change cell number format in VBA
    By hemi_fan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2010, 06:05 PM
  7. change number format based on another cell?
    By Fidd$ in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-18-2009, 10:02 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