+ Reply to Thread
Results 1 to 3 of 3

Code to check if a string is formatted correctly as a part number

  1. #1
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Code to check if a string is formatted correctly as a part number

    I have a formula I can use that checks the value in cell A2 to see if it contains a proper part number, formatted as four digits, a dash, and four more digits, like so: "0000-0000". This formula does that nicely, it returns "yes" or "no":

    Please Login or Register  to view this content.
    I would like a way to perform this logical test inside of VBA code, without having to add a column and insert this formula on the sheet directly. If I assign Range("A2").value to the variable "PartNumber", how would I write the above formula as an "If Then" code? What would I replace the "??????" with below?

    Please Login or Register  to view this content.
    Any help would be appreciated, thanks!

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,511

    Re: Code to check if a string is formatted correctly as a part number

    Try this:
    Please Login or Register  to view this content.
    BSB

  3. #3
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Code to check if a string is formatted correctly as a part number

    Works perfectly, thanks! :D

+ 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. Code to check if form object (shape) exists not working correctly?
    By Belinea2010 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-13-2018, 03:48 PM
  2. [SOLVED] Check if part of string is a number or letter
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2015, 09:13 AM
  3. [SOLVED] Dates to String but Cell formatted as Number
    By Klaster in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-25-2014, 07:32 AM
  4. Check if the last part of entered string is an Integer
    By szpt9m in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-08-2014, 11:08 PM
  5. VBA code to check format of conditionally formatted cell
    By macquarl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2008, 11:52 AM
  6. Convert Formatted Number to String
    By Rob169 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-24-2007, 12:35 PM
  7. [SOLVED] Formatted Number into String Variable, Excel VBA
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2006, 07:25 PM

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