Consulting

Results 1 to 7 of 7

Thread: Solved: Problem in using Custom Format through VBA

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location

    Solved: Problem in using Custom Format through VBA

    Hi,

    I am trying to change a cells display format through custom format option in a workbook. It works like this --a macro will change the target cell's display based on adjacent cells value.

    In attached model in Cell “H9” has a value of 2000. Its adjacent cell has a text as “LTM”. By using a macro code I want to change the display format of H9 as LTM. But macro is taking “M” in “LTM” as month for the year 2000 and changing display format as “LT6”.

    Please help me how to avoid excel reading “M” as month.

    Advance Thanks,
    Suresh
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There is nop suh format as LTM that I am aware of. How do you want H9 to show as?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location
    Hi Xld,

    I want to show Cell H9 as "LTM" or "FY"

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Sub Custom_Format()

    Dim x As String
    Dim rng As Range

    Set rng = Range("H9")

    x = """" & rng.Offset(0, 1).Value & """"
    rng.NumberFormat = x

    rng.Select
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location
    Thanks Xld, It is working fine.

  6. #6
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location
    How can name this thread as "solved". I am not seeing any buttons.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Above the threads is a Thread Tools dropdown. It is there.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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