Consulting

Results 1 to 15 of 15

Thread: Check if cell has custom format using UDF

  1. #1

    Check if cell has custom format using UDF

    Hello everyone
    Is there a way that enables me using UDF for example to check if the cell has custom format or not?
    It would return True or False
    Example : A5 custom format ;;;
    In B5 I imagine putting a UDF that checks A5 to see if it is formatted in custom format or not

    Thanks advanced for help

  2. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    What kind of custom format?
    Font name or color?
    cell color or border?
    cell Horizontal or verticle alighment?
    Number format?
    Conditional format?
    There are a dozen or so possibilities
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Thanks a lot for reply
    I mean when right-click on cell then Click "Format Cells" then select "Custom" ...

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you use the worksheet CELL function?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Quote Originally Posted by mdmackillop View Post
    Can you use the worksheet CELL function?
    I don't know a lot about it. Can you show me how to adapt CELL to that task? Or it is better to devise new UDF?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    See here
    MsgBox Evaluate("Cell(" & Chr(34) & "Format" & Chr(34) & ", A1)")
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    That's great start point
    I have formatted the cell A1 in that way ;;; and the result was "H" >>> I think it refers to hidden and this is not included in the link above
    another point how can adapt this to check for the Custom only ... away from other customs. i think I may use Select Case to include all possible common formats but I can't figure it out

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Something like this : etc. line to be completed
    Function MyFormatTest(Cel As Range) As String
    
    
    Select Case Evaluate("Cell(" & Chr(34) & "Format" & Chr(34) & "," & Cel.Address & ")")
    Case "G"
    MyFormatTest = "General"
    Case "F0", ",0" 'etc.
    MyFormatTest = "Other"
    Case Else
    MyFormatTest = "Custom"
    End Select
    End Function
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Yes that's exactly what I was searching for. Now it is solved
    Thank you very much Mr. MD
    Best Regards

  10. #10
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Quote Originally Posted by YasserKhalil View Post
    Thanks a lot for reply
    I mean when right-click on cell then Click "Format Cells" then select "Custom" ...
    OK. That would be NumberFormat

    Code for standard Module
    Public Function HasCustomNumberFormat(Cell As Range) As Boolean
      HasCustomNumberFormat = Not Cell.NumberFormat = "General"
    End Function
    Returns True or False
    Usage: to check Cell A1.
    In another cell formula = "=HasCustomNumberFormat(A1) "
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  11. #11
    Thanks a lot SamT for reply .. But this UDF returns False to General only and any other format returns True ..
    The main target is the Custom format .. and other formats would return False

  12. #12
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Aah.

    Well, it was written for Excel XP.

    Use mdmackillop's.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  13. #13
    Thanks a lot
    What XP stands for? Forgive me as English is not my native language .. Do you mean experts?

  14. #14
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Excel XP = Excel 2002
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  15. #15
    Thanks a lot and forgive me for my little experience

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •