I have a 5 character code that needs to be converted to a 4 character code. Additionally, the 5th character is either a 1, 2 or 5, and I need to convert them to 1, 5 or 9. As an example, if my query returns '20155', I need to translate that to '2159'. So far I have:
select substr(fieldname,1,1) || substr(fieldname,3,2) || substr(fieldname,-1,1) as newfieldname
This converts it from 5 to 4 characters. What I don't know how to do is also change the last character to the new value as described above.
A sample of what I want it to achieve is:
20141 becomes 2141
20142 becomes 2145
20145 becomes 2149
20151 becomes 2151
20152 becomes 2155
20155 becomes 2159
Any assistance would be appreciated. I am not a computer programmer - I am a functional analyst that has to validate over 500,000 rows of data, each row containing the fieldname above.
You can use "case when ":
Case when 2 then 5 , etc...
Related
20/11/2022 12:00:52 2 X 15.95 15.95 USD 57 5 689 5 689 1 4111 0 Amazing Lego Team
I need to get the position of No 4111 in the above text string, As an excel beginner any help will be greatly appreciated. Thanks.
All of the Text Strings will have a 4 digit number like 4111 which i have to get the position for.
Have tried using this formula to get four digit number in another column, LOOKUP(10^15,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),5)+0) but I am looking to get position instead.
I have tried using lookup but I could only go so far as a beginner.
Use the formula you provided =LOOKUP(10^15,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),5)+0) to identify the number, and use FIND to get the position of the number.
Cell A1="20/11/2022 12:00:52 2 X 15.95 15.95 USD 57 5 689 5 689 1 4111 0 Amazing Lego Team"
=FIND(LOOKUP(10^15,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),5)+0),A1)
=58
This looks to be in a space (or some other character) delimited text string. If you have a bunch of rows of data like this, use the Text to Columns feature on the Data tab. Use the Delimited option and then click the check box next to space (or other if it's something custom not in the available options) and Excel will split the data into columns for you.
For your string example, if you know that your 4 digit is started 58 char from the beginning of the string, use =MID(A1,58,4) A1 is the cell with your string.
MID function returns a specific number of characters from a text string, starting at the position you specify, based on the number of characters you specify.
=LET(t,TEXTSPLIT(A1,," "),
FIND(FILTER(t,(LEN(t)=4)*(ISNUMBER(--(t)))),A1))
It splits the string at every space and filters the result for being of length of 4 characters and not being an error if converted to number.
20/11/2022 12:00:52 2 X 15.95 15.95 USD 57 5 689 5 689 1 4111 0 Amazing Lego Team
I need to get the position of No 4111 in the above text string, As an excel beginner any help will be greatly appreciated. Thanks.
All of the Text Strings will have a 4 digit number like 4111 which i have to get the position for.
Have tried using this formula to get four digit number in another column, LOOKUP(10^15,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),5)+0) but I am looking to get position instead.
I have tried using lookup but I could only go so far as a beginner.
Use the formula you provided =LOOKUP(10^15,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),5)+0) to identify the number, and use FIND to get the position of the number.
Cell A1="20/11/2022 12:00:52 2 X 15.95 15.95 USD 57 5 689 5 689 1 4111 0 Amazing Lego Team"
=FIND(LOOKUP(10^15,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),5)+0),A1)
=58
This looks to be in a space (or some other character) delimited text string. If you have a bunch of rows of data like this, use the Text to Columns feature on the Data tab. Use the Delimited option and then click the check box next to space (or other if it's something custom not in the available options) and Excel will split the data into columns for you.
For your string example, if you know that your 4 digit is started 58 char from the beginning of the string, use =MID(A1,58,4) A1 is the cell with your string.
MID function returns a specific number of characters from a text string, starting at the position you specify, based on the number of characters you specify.
=LET(t,TEXTSPLIT(A1,," "),
FIND(FILTER(t,(LEN(t)=4)*(ISNUMBER(--(t)))),A1))
It splits the string at every space and filters the result for being of length of 4 characters and not being an error if converted to number.
I'm trying to create a CSV file of one of my customer's serial numbers. We print them as barcodes for them to use, and normally I'd use our barcode software to generate the numbers. However, we're using a different method of printing, and it requires a CSV/Excel file of all the numbers to be printed. The barcode is as follows:
MC100VGVA.
The last digit is a check digit created from the rest of the string.
Now, my problem comes with the "VGVA" bit. Column A is the prefix (MC), Column B is the number (100), Column C is the incrementing 4 characters (VGVA), and Column D is the check digit.
I need for the VGVA bit to increment alphanumerically. So, when it gets to VGVZ, I need it to go to VGW0. Then when it gets to VGZZ, it needs to go to VH00 and so on until they reach ZZZZ, in which the next digit would increase Column B to 101, and Column C would become 0000.
I've attempted to use the CHAR formula, as well as CONCATENATE, and MID. But, because I'm not well versed in these formulas, my attempts at editing them to work with 4 digits have been failing me.
I'm not opposed to using VBA if needed, but it's not something I've ever worked with, so you'll have to forgive any ignorance on my part.
Please let me know if you need more information. Thanks!
It looks like you are trying to create a new base, the one based on 27 digits (0 and all letter from 'A' to 'Z'). So I'd advise you to create a conversion from and to 27-digit system.
Let me first explain you what I mean in octal numbering (8 digits, from 0 to 7): in that system we start from (just some examples):
a=0011
b=1237
c=1277
The meaning of those numbers is:
a equals 0*8^3 + 0*8^2 + 1*8^1 + 1*8^0 = 9, so:
a+1 equals 10, and converting this to octal numbering yields:
0012
b equals 1*8^3+2*8^2+3*8^1+7*8^0 = 671, so:
b+1 equals 672, and converting this to octal numbering yields:
1240
c equals 1*8^3 + 2*8^2 + 7*8^1 + 7*8^0 = 703, so:
c+1 equals 704, and converting this to octal numbering yields:
1300
I propose to do exactly the same for your 27-digit system, with following example:
VGZZ equals 22*27^3 + 7*27^2 + 26*27^1 + 26 = 438857
VGZZ+1 equals 438858, and converting this to 27-digit numbering yields:
VH00
You can do this, using a VBA function you need to develop yourself. The converting from the string to the normal number is obvious, and in the other way around, you use =MOD(...,27^3) and other similar functions.
I believe I've found a non-VBA answer to this question, thanks to someone on another forum.
Here's what they suggested and it seems to be working perfectly:
B2
=B1+(C2="0000")
C2
=RIGHT(BASE(DECIMAL(C1,36)+1,36,4),4)
and maybe try this at D1
=MID("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%",MOD(SUMPRODUCT(SEARCH(MID((A1&B1&C1),ROW($1:$99),1),
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%") )-99,43)+1,1)
I have an Excel spreadsheet with over 2000 entries:
Field B1: CustomerID as 000012345
Field B2: CustomerID as 0000432
Field C1: CustomerCountry as DE
Field C2: CustomerCountry as IT
I need to build codes 13 digits long including "CustomerCountry" + "CustomerID" without leading 0 + random number (can be 6 digits, more or less, depends in length of CustomerID).
The results should be like this: D1 Code as DE12345967895 or D2 Code as IT43274837401
How to do it with Excel functions?
UPDATED:
I tried this one. My big problem is to say that random number should be long enough to get 13 characters in all. Sometimes CustomerID is just 3 or 4 digits long, and concatenation of three variables can be just 10 or 9 characters. But codes have to be always 13 characters long.
Use & to concatenate strings.
Use VALUE(CustomerID) to trim the leading zeroes from the ID
Use RAND() to add a random number between 0 and 1 or RANDBETWEEN(x,y) to create one between x and y.
Combine the above and there you are!
If you always want 13 digits you can use LEFT(INT(RAND()*10^13);(13-LEN(CustomerCountry)-LEN(VALUE(CustomerID)))) for the random number to ALWAYS be the right length.
total formula
= CustomerCountry
& VALUE(CustomerID)
& LEFT(INT(RAND()*10^13);(13-LEN(CustomerCountry)-LEN(VALUE(CustomerID))))
=C1 & TEXT(B1,"0") & RIGHT(TEXT(RANDBETWEEN(0,99999999999),"00000000000"),11 - LEN(TEXT(B1,"0")))
that should do it
I don’t understand what is where and OP has accepted answer so have not bothered testing:
=LEFT(RIGHT(C1,2)&VALUE(MID(B1,15,13))&RANDBETWEEN(10^9,10^10),13)
(but I might revert to this if no one else picks the flaws in it first!)
I am trying to convert a single column of numbers in excel to multiple depending on the content.
e.g. Table 1 contains 1 column that contains 1 or more numbers between 1 and 11 separated with a comma. Table 2 should contain 11 columns with a 1 or a 0 depending on the numbers found in Table 1.
I am using the following formula at present:
=IF(ISNUMBER(SEARCH("1",A2)),1,0)
The next column contains the following:
=IF(ISNUMBER(SEARCH("2",A2)),1,0)
All the way to 11
=IF(ISNUMBER(SEARCH("11",A2)),1,0)
The problem with this however is that the code for finding references to 1 also find the references to 11. Is it possible to write a formula that can tell the difference so that if I have the following in Table 1:
2, 5, 11
It doesn't put a 1 in column 1 of Table 2?
Thanks.
Use, for list with just comma:
=IF(ISNUMBER(SEARCH(",1,", ","&A2&",")),1,0)
If list is separated with , (comma+space):
=IF(ISNUMBER(SEARCH(", 1,", ", "&A2&",")),1,0)
A version of LS_dev's answer that will cope with 0...n spaces before or after each comma is:
=IF(ISNUMBER(SEARCH(", 1 ,",", "&TRIM(SUBSTITUTE(A2,","," , "))&" ,")),1,0)
The SUBSTITUTE makes sure there's always at least one space before and after each comma and the TRIM replaces multiple spaces with one space, so the result of the TRIM function will have exactly one space before and after each comma.
How about using the SUBSTITUTE function to change all "11" to Roman numeral "XI" prior to doing your search:
=IF(ISNUMBER(SEARCH("1",SUBSTITUTE(A2, "11", "XI"))),1,0)
If you want to eliminate "11" case, but this is all based on hardcoded values, there should be a smarter solution.
=IF(ISNUMBER(SEARCH(AND("1",NOT("11")),A2)),1,0)