+ Reply to Thread
Results 1 to 8 of 8

how to automate this...

  1. #1
    Registered User
    Join Date
    02-22-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    1

    how to automate this...

    Hi all~

    I am trying to automate this function, and I don't know where to go about designating the properties, either functions or formats. What I am trying to do is to automate a column so it inserts the following format V.#/no.#, when I type in the numbers with a comma, or slash, or semi-colon to separate them out.

    In other words, in case that wasn't clear, I want to be able to enter the numbers and have excel display it as V.#/ no.#. for example I type 2/4 (where the slash indicates the separation of the numbers,) and have excel change it to V.2/no.4, (volume 2/ number 4.)

    Can it be done? any help would be appreciative.

    Arron
    Last edited by VBA Noob; 02-22-2009 at 05:55 PM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: how to automate this...

    Hi Arron,

    You could try the code shown below. Right-click on the worksheet tab for which you want the code to run, and select View Code. Paste the code below then close the VB Editor window.

    The code is looking for any change in column A, and you should enter your numbers separated by a decimal, e.g. 43.56
    Please Login or Register  to view this content.
    It should work as requested, and if invalid data is entered it will tell you so, as well as undo that invalid entry.

    Hope that helps!

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: how to automate this...

    You could adatp pjoaquin's code slightly to handle multiple delimiters, I think you said you might want to use any of: ; / .

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-23-2009
    Location
    Somerset, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: how to automate this...

    Hi Arron,

    I've probably read your question differently from the other two posters as my solution is much simpler, although probably a lot more limited. I've tested it on 2007 but am unsure of compatibility on the 2003 version.

    Format Cells > Number and under category select Custom

    In 'type' copy and paste: "V."0"/no."#

    Click OK

    You can then type to the cell and it would automatically be formatted. You cannot add a comma, slash or colon, and you are limited to up to only 10 parts (only the last digit is included for the 'no', part)

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: how to automate this...

    gdfiler,

    I totally agree with you that if you assume only one delimiter (period) then using a Custom Format is definitely the way to go (I believe multiple are required in this instance hence the latter VBA routine).

    Re: Custom Format I think you have some typo(s), no ?

    If you enter 4.2 the following custom format:

    "V."0"/no."#

    Would generate: V.0/no.4

    I think perhaps it should be:

    "V."0"/no".#

    which would generate V.4/no.2

    Custom Format would work the same pre2007.
    Last edited by DonkeyOte; 02-23-2009 at 07:48 AM.

  6. #6
    Registered User
    Join Date
    02-23-2009
    Location
    Somerset, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: how to automate this...

    Hi DonkeyOte,

    Thanks for taking the time to look at my suggestion. I'm afraid I don't fully understand what you mean by delimiter but you are right in saying that when you type 4.2 into the a cell with my custom formatting applied, the incorrect cell value will be shown.

    This is not because of a typo however but rather I didn't factor a separator in when working this out. Your suggestion of "V."0"/no".# works well if the "." is used as a separator, and "V."0"/no".### removes the issue of being limited to only 9 parts.

    G.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: how to automate this...

    Quote Originally Posted by gdfiler
    ...I'm afraid I don't fully understand what you mean by delimiter
    To clarify by delimiter I was referring to the character the OP chooses to insert to act as a separator between values... that is to say the character entered to split say 4 and 2... the first post on the thread implies he/she may vary that separator but still expect the same result.. ie entering any one of:

    4.2
    4;2
    4/2

    should generate V.4/no.2

    If we take the stance that the OP will only ever adopt the first method illustrated (ie period separator -> 4.2) a Custom Format certainly becomes a viable and attractive option!

    The key difference between the VBA & Custom Format method is of course the value that persists in the cell after the respective method is applied...

    With VBA the underlying cell value becomes V.4/no.2 literally whereas with a Custom Format the underlying value persists as entered (ie 4.2), it is merely the display that is altered.

    Establishing which of the two approaches to be preferable depends entirely upon how the source data is to be used subsequently - it may be that the literal text string is required or it may be the case that retaining the value as entered is preferable - unfortunately this is not specified.

    Hope that makes more sense...

  8. #8
    Registered User
    Join Date
    02-23-2009
    Location
    Somerset, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: how to automate this...

    Thank you DonkeyOate for clearing that up for me. I hope Arron, that a suitable solution for your problem, is contained in this thread!

    G.

+ 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