+ Reply to Thread
Results 1 to 2 of 2

check format of cells using if statement - "custom" format

  1. #1
    Registered User
    Join Date
    10-30-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    52

    check format of cells using if statement - "custom" format

    Hiya,

    I'm having trouble with some code.
    Data is downloaded from a machine in "custom" format. The cells show "5.5" but if you click in them, the bar shows that the number is actually "5.455", so I suppose that is the customised part. This is fine and data can be analysed in custom format. Later in the macro, I format the data as "number", showing all 3 decimal places in the cells. Format= "0.000"

    I need to create an error checking section of the macro.
    I need to ensure that no one accidentally types another symbol into the data. For example, "%5", "5%" , "5£", or "£5". I am error checking using "if Not IsNumeric then... msg box"
    This check works for "%5" and "5£", however if "5%" is into a cell then the format changes to be in percentages and the IsNumeric function fails.

    I therefore want to write this code out correctly
    Please Login or Register  to view this content.
    I know that the only line that doesn't work is :
    If Not Ccell.NumberFormat = "custom" And Not Ccell.NumberFormat = "0.000" Then
    because if I write "if Ccell.NumberFormat = "0%" it displays the msg. (i don't want to have to do this for currency, time, etc)

    Currently, the code just says all the custom format cells are errorenous, so " Ccell.NumberFormat = "custom" " clearly doesn't work!!

    please can anyone help me? XXX

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: check format of cells using if statement - "custom" format

    Have you tried just:
    if not Ccell.NumberFormat = "0.000"
    without the custom part?

    Note, in your code you compare the same property (numberformat) against two different values, it can only be one of them so everything will display the error message. When you select a custom format, the numberformat is set to the custom format you type in - use the macro recorder and record yourself changing the cell format if you are unsure what it would be in VBA.

+ 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: 2
    Last Post: 11-01-2012, 04:35 PM
  2. Excel 2007 : Format cells as "custom" 5 digits
    By MyronCope in forum Excel General
    Replies: 1
    Last Post: 06-01-2010, 09:27 AM
  3. [SOLVED] Format a column wihtout using "Format-Cells-Number-category-etc"
    By serve in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-23-2006, 09:00 PM
  4. [SOLVED] Format a column wihtout using "Format-Cells-Number-category-etc"
    By serve in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-23-2006, 10:45 AM
  5. Replies: 1
    Last Post: 07-18-2005, 03:05 PM

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