+ Reply to Thread
Results 1 to 4 of 4

VBA code for multiple formats

  1. #1
    Registered User
    Join Date
    07-27-2005
    Posts
    8

    VBA code for multiple formats

    Trying to find an Excel VBA code that will automatically do the following:

    If cell o9 = "410", then go to cell K6 and format it as a whole number; otherwise, format k6 as currency ($) with no cents.

    Please note the user will be entering a value into cell k6. I prefer not having the user change the format.

    Ideally I thought I could do this in "format-cell-number-custom", but no luck. If I can please let me know-That is my first choice. Note also my conditional formatting does only the color, bold, etc. stuff.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Try this event driven macro which you need to paste into the appropriate sheet tab in the VBA editor - SHIFT F11.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-27-2005
    Posts
    8
    Martin, I posted the code into the sheet, but nothing fired. Suggestions? Please note that I have a formula in O9, which is:

    =IF(H6="Ale","790",IF(H6="Wine","410",IF(H6="Ale & Wine","790 & 410","")))

    Also note the worksheet is password protected, and has cells that are both locked and unlocked. Cells H6, K6 and O9, however, are not locked.

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Try this slight variation

    Please Login or Register  to view this content.
    The reason that the previous version didn't work was that it was expecting direct input into cell 09 rather than the result of a formula. The macro now will trigger when any change is made to the sheet.

+ 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