VBA Columnar Loops Using Arrays for String Variables - excel

I have a column full of text/string values. Some of the values appear to be null, but in reality have some formatting (additional spaces) left over from the exporting program where I get the excel data. I am trying to create an array using all capitalized letter of the English alphabet to cypher through each cell in the column, looking for the instance of any of the alphabet's letters within the first letter of each cell in the specific column, and if not found, returning a completely blank value in the neighboring column. If a letter value is found, then it would return the entire value of the cell. This way I can have true blanks and will be able to sort things a bit better.
I have been trying to find a working argument to build off of but aside from the
LEFT(Cell,1)="A-Z"
I have found little that seems to be a viable workaround. Any help is appreciated! Thanks!

You will want to use the ascii value to check for A-Z. Assuming the data is in the A column you can use the formula below. ASCII value range 65=A 90=Z. The trick is the Code formula which returns the ascii numeric value. Then an if statement to check if it is between the range, If it is return the cell contents and if not return nothing. You can also use Clean() to remove any unprintable characters (that is not used in this example)
=IF(CODE(UPPER(LEFT(A1,1))) > 64, IF(CODE(UPPER(LEFT(A1,1))) < 91,A1,""))

Related

Write data from a list if the adjacent cell contains certain string

I need to update hundreds of cells, and that would be trivial automating, but I am not being able to make it work.
I have a list like the following:
And, in a different tab, a list I have to populate with values above (in B) based on the appearance of the twitter handle in other column.
The names are within a long text string (all of them begin with #), and it is not possible to re-order the list based on those names. Also, there are more names than values, so some cells will remain blank.
Is there a way I can write a formula that writes the values of the first list into the second one if the name in column A in that row is contained within the adjacent string?
Thanks!
You can refer to this sample formula (Same sheet was used):
=arrayformula(if(C2:C<>"",iferror(vlookup(REGEXEXTRACT(C2:C,"\B\#\w+"),A2:B,2,false),""),""))
What it does?
Use array formula to loop column C values
Extract the twitter name (string that starts with #) using Regexextract()
Use the extracted #twittername as search key to get the connections value using vlookup()
Output:
Since we don't have access to the spreadsheet, I can't know for sure what the line-break character is within the Col-A cells of your second sheet. And using this line-break character is important, since Twitter handles may use some non-alphanumeric characters such as the underscore and others which are not included in such REGEX notation as \w. I'm assuming here that the line-break character is CHAR(10) from the ASCII chart.
I also don't know the name of your first sheet; so here, I've just written it as Sheet1. You'll need to replace that with your actual sheet name, remembering to place it in single quotes if it contains anything but alphanumeric characters (e.g., 'Data Sheet').
That said, delete everything from Col-B in your second sheet (including the header "Connections") and place the following formula in cell B1 of that second sheet):
=ArrayFormula({"Connections"; IF(A2:A="",, IFERROR(VLOOKUP(REGEXEXTRACT(SUBSTITUTE(A2:A,CHAR(10),"~"),"#[^~]+"),Sheet1!A:B,2,FALSE)))})

Excel Formula separate the left numeric values from the data

I have some data in Col"K" where from i am just trying to get the left characters as i tried in Col"H" using formula.
But what i used is Left function like =Function(cell,10) that is not the correct way characters can be more than 10 or less than 10.
1st formula should be dynamic to get the left numeric values.
2nd Formula should copy and paste the same numeric values until next value comes as available in Col"I"
I tried to make it but what i can do is to create left function and do not know how to develop it dynamic.
Any help will be appreciated.
Sheet Link
https://docs.google.com/spreadsheets/d/1nJZeWDZ0EWgmWB0z17xU93fjIOFsu46EL37IJqJzZ_0/edit?usp=sharing
This formula should do the job.
[J2] =IFERROR(TRIM(LEFT(L2,FIND("-",L2)-1)),J1)
Note that it will fail if placed in row 1 and there is no dash in L1.
Use find function to get numeric characters length.
=iferror(trim(left(L3,FIND("-",L3)-1)),M2)
Here we are finding the separator "-" in your text and it gives us index number of separator.
Then picking text from start to before index number i.e., Numeric value and removing blank spaces, if any, using trim function. If we don't have number/separator in the text then showing previous cell value using iferror function. So, Make sure first row always has numeric value.
Same has implemented in the sheet you have shared
As per the latest data I have updated my answer as below , now it is checking output is numeric or not:
=IF(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},J9))=0,K8,TRIM(LEFT(J9,FIND("-",J9)-1)))

Unable to convert text to Numbers

I've been given an excel to import on Database, it was exported from an Access DB. in the excel there's a column type_class, in one excel it's good(sheet1), but on another excel which I moved to sheet2 to make VLOOKUP function, I can't tell whether it's a text or a number column from the first sight. the upper-left green-thing is not showing on all cells. but, using ISTEXT function result in text. below is the original column without any changes or formatting, as well as ISTEXT result.
when I use the column in a VLOOKUB function to transfer the Name to the first sheet, only (1010, 1101, 1102,....), hence the cells with the green-mark on the upper-left corner.
I can easly format the key in sheet1 using text-to-columns, cell formatting, and any other way.
but I cannot change the column in sheet2, I tried:
Text-to-Columns
Cell Formatting
VALUE(text), CLEAN(text), TRIM(text), TRIM(CLEAN(text)), CLEAN(SUBSTITUTE())
Multiply by 1
but only the cell with the green-mark changes to a number, the rest stays the same. I browsed the internet but didn't get a solution either.
Edit:
I uploaded what is need to test the case on the drive. you can find it here
Help Appreciated
For your digit strings that you can't convert to text, from the comments it seems there are extra characters in that string not removable by TRIM or CLEAN.
Determine what those character are
Assume a "non-convertible" digit string is in A1
Enter the following formula
B1: =MID($A$1,ROWS($1:1),1) and fill down
C1: = UNICODE(B1) and fill down
From this you can determine the character to use in a SUBSTITUTE function.
For example:
From the above we see that the character code that we need to get rid of is 160.
So we use:
=SUBSTITUTE(A1,CHAR(160),"")
or, to convert it in one step to a number:
=--SUBSTITUTE(A1,CHAR(160),"")
Note If the character code is >255, use UNICHAR instead of CHAR in the SUBSTITUTE function.
Without an example, I use value() to convert what excel takes as text like so:
=value(left(“10kg”,2))
Or the following also works:
=left(“10kg”,2)*1
Note those double quotes should be the straight ones - sorry smartphone is not always smart...
And if leading or trailing spaces are an issue, then trim() is one solution.

Excel Formula_Matching

I am trying to build an excel formula, that will reference another column based off of the first word. The first word does not need to have an exact match, it will however, need to find words that are “very similar” to each other. If the words, are not a close match, I would need the original cell to show in the results tab (as seen below). I would need the excel formula to do the following:
Column A......….Column B (with desired info)......….Column C (results)
Upper Body...……….Upper...………………......………………......……Upper
Upper Arms...…………….....………………......………………......…… Upper
Upper Legs...…………….....………………......………………......…… Upper
Lower Legs...…………….....………………......………………......…… Lower Legs
I have tried, the VLookup with the range lookup, as “True”, however the above example will be a lot more complex, with the real data set I am using. Any help would be greatly appreciated.
You can extract first word and then use Index() and Match().
You will first need to get the first word of column A. You can do this by splitting column A by a delimiter (split after first space) or by using a formula.
Formula example: =IF(ISERR(FIND(" ",A2)),"",LEFT(A2,FIND(" ",A2)-1)) where A2 is the cell you are looking at.
When you have that value you can then use =Index(Match()) to look up value. Match allows for fuzzy matching as long as you do not set the last parameter to 0.

Testing if first character of a string is non-numeric in LibreOffice Basic

I have column of strings mostly composed of numbers. Most of these strings are indeed 10 digit numbers formatted as string like :1234567890 except a few of them. Those exceptions start with a literal character with a letter to be specific like :A1234567890. What I want to do is while looping over that column I want to check on first characters and if it is a literal I want to branch my code. I'm not familiar with LibreOffice Basic yet VBA so any help is appreciated.
Listing 6.14. Display all data in a column in Andrew Pitonyak's Macro Document shows how to loop through all cells in a column.
To find out if the cell's string is numeric, use the IsNumeric function:
If IsNumeric(aCell.String) Then

Resources