How can I make Excel ignore special characters and spaces when taking data from another cell?

Adam W

I have an Excel workbook which is used to produce quotations for customers. It automatically generates a unique quotation number based on the salesperson's name, the name of the company receiving the quotation, the date, and the issue number (if two separate quotations are being made by the same salesperson, for the same company, on the same day, the first will have the issue number 01, the second will have the issue number 02, etc.)

Filled with dummy information, a typical quotation number will look like this:

JS-ABC-05052016-01

The 'JS' is the initials of the salesperson (John Smith.) The 'ABC' is the first three characters of the company name (ABCompany.) The '05052016' is today's date, and '01' is the issue number. This is all information entered by the salesperson.

The formula used in the cell which generates and displays the quotation number is:

=UPPER(LEFT(P4,1)&LEFT(P5,1)&"-"&LEFT(D11,3)&"-"&LEFT(K6,2)&MID(K6,4,2)&MID(K6,7,4)&"-"&D5)

The above formula is taking pieces of information that are entered in cells, and compiling them to generate the quotation number.

There is an issue, however, when the first three characters of the company name contains a blank space, or a special character. For example, a company name of 'A. B. Company' would generate the following quotation number:

JS-A. -05052016-01

Another example is that a company name of 'A&B Company' would generate the following quotation number:

JS-A&B-05052016-01

Further along in the quotation process, the workbook will be renamed to contain the quotation number. This can cause issues where the quotation number contains a special character such as a period (for example, it can mess up the file type.)

Is there a way to make Excel ignore any characters (including spaces) in the company name that aren't letters or numbers? For example, making a company named 'A. & B. Company' generate the quotation number:

JS-ABC-05052016-01

mirusev

I think I've found the answer for you

Function removeSpecial(sInput As String) As String
    Dim sSpecialChars As String
    Dim i As Long
    sSpecialChars = "\/:*?""<>|$&"
    For i = 1 To Len(sSpecialChars)
        sInput = Replace$(sInput, Mid$(sSpecialChars, i, 1), " ")
    Next
    removeSpecial = sInput
End Function

Alt+F11 - Insert - Module - Paste it in.

You can add more special characters into the array if you wish. here: sSpecialChars = "\/:*?""<>|$&"

Then in your cell, type: =SUBSTITUTE(removeSpecial(A1)," ","")

the result of a &b.company is ab.company

Credits to the author, I've just found it.

then your formula should be:

=UPPER(LEFT(SUBSTITUTE(removeSpecial(P4)," ",""),1)&LEFT(SUBSTITUTE(removeSpecial(P5)," ",""),1)&"-"&LEFT(SUBSTITUTE(removeSpecial(D11)," ",""),3)&"-"&LEFT(SUBSTITUTE(removeSpecial(K6)," ",""),2)&MID(SUBSTITUTE(removeSpecial(K6)," ",""),4,2)&MID(SUBSTITUTE(removeSpecial(K6)," ",""),7,4)&"-"&SUBSTITUTE(removeSpecial(D5)," ",""))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to ignore special characters and spaces in string?

From Dev

How can I make Excel fetch data from a database automatically when I open the spreadsheet?

From Dev

How can I ignore Excel cell value if text is struck through?

From Dev

how to ignore spaces when retrieving data from mysql table

From Dev

How can i delete from a text file these special characters

From Dev

How can I make a special file that executes code when read from

From Dev

How can i duplicate rows in excel and copy value from one cell to another?

From Dev

How can I ignore spaces in a substring?

From Dev

Can you make Excel Change Another Cell's Colour When This Cell is Clicked?

From Dev

How can I logically test the format of another cell in excel

From Dev

How can I make an Excel cell with a DATE format accept dashes?

From Dev

How can I make this only match the words after the word 'speaks' and ignore commas and spaces

From Dev

How can I retrieve a specific cell value from another Excel sheet using this complex logic that find the row using another value?

From Dev

how to ignore special characters when using word boundry

From Dev

Converting varchar to decimal when various special characters exists in data originating from excel

From Dev

Regex in Excel VBA Special Characters and Embedded Spaces

From Dev

How can I split data in a cell to existing columns on Excel?

From Dev

Make Autohotkey ignore any special characters in string

From Java

How can I automatically add the data of one cell to another cell on another sheet?

From Dev

How can I add columns of data from one table to another from a lookup ID number in CSV/Excel?

From Dev

How to remove text/characters from an Excel cell

From Dev

How to remove text/characters from an Excel cell

From Dev

Excel, transfering data from one cell to another

From Dev

How can I make a regular expression that contains special characters, like word boundaries, with a variable?

From Dev

How can I make a batch script supply a password with special characters to an external application?

From Dev

How can I make a regular expression that contains special characters, like word boundaries, with a variable?

From Dev

How can I parse a string from a cell multiple time in excel?

From Dev

How can I link excel cell to updated value from web?

From Dev

How can I replace special characters by column value in every row in excel?

Related Related

  1. 1

    How to ignore special characters and spaces in string?

  2. 2

    How can I make Excel fetch data from a database automatically when I open the spreadsheet?

  3. 3

    How can I ignore Excel cell value if text is struck through?

  4. 4

    how to ignore spaces when retrieving data from mysql table

  5. 5

    How can i delete from a text file these special characters

  6. 6

    How can I make a special file that executes code when read from

  7. 7

    How can i duplicate rows in excel and copy value from one cell to another?

  8. 8

    How can I ignore spaces in a substring?

  9. 9

    Can you make Excel Change Another Cell's Colour When This Cell is Clicked?

  10. 10

    How can I logically test the format of another cell in excel

  11. 11

    How can I make an Excel cell with a DATE format accept dashes?

  12. 12

    How can I make this only match the words after the word 'speaks' and ignore commas and spaces

  13. 13

    How can I retrieve a specific cell value from another Excel sheet using this complex logic that find the row using another value?

  14. 14

    how to ignore special characters when using word boundry

  15. 15

    Converting varchar to decimal when various special characters exists in data originating from excel

  16. 16

    Regex in Excel VBA Special Characters and Embedded Spaces

  17. 17

    How can I split data in a cell to existing columns on Excel?

  18. 18

    Make Autohotkey ignore any special characters in string

  19. 19

    How can I automatically add the data of one cell to another cell on another sheet?

  20. 20

    How can I add columns of data from one table to another from a lookup ID number in CSV/Excel?

  21. 21

    How to remove text/characters from an Excel cell

  22. 22

    How to remove text/characters from an Excel cell

  23. 23

    Excel, transfering data from one cell to another

  24. 24

    How can I make a regular expression that contains special characters, like word boundaries, with a variable?

  25. 25

    How can I make a batch script supply a password with special characters to an external application?

  26. 26

    How can I make a regular expression that contains special characters, like word boundaries, with a variable?

  27. 27

    How can I parse a string from a cell multiple time in excel?

  28. 28

    How can I link excel cell to updated value from web?

  29. 29

    How can I replace special characters by column value in every row in excel?

HotTag

Archive