Identify type of data based on first couple of characters in a cell - excel

I have a range of 412 cells (A1: A412). Each cell has a string of data that I OCR'd and exported to Excel. It is a list of names and addresses.
I need VBA code that will loop through each cell, look at the first 5 or 6 characters and determine if the string of text is a Name, Address or City (state&zip) and transpose that data out.
I have code that will transpose the data after every n number of rows, but the data does not get exported this way. Ex: the name might take up two different cells, but I want to merge those two cells in the process.
For example: public information from a state government source
CURRENT LIST (Sheet 1):
Cell A1: A. E. Ewell Investment Co.
Cell A2: P.O. Box 27
Cell A3: Ardmore, OK 73402
Cell A4: Aimie A. Akers, Trustee of the Howard A.
Cell A5: and Aimie A. Akers Revocable Joint Trust
Cell A6: Agreement dated 5/03/1996
Cell A7: 11 Nichols Road
Cell A8: Luray, VA 22835
Cell A9: Alison Evans Taylor
Cell A10: And James Andrew Taylor
Cell A11: 1523 Glenwood Avenue
Cell A12: Oklahoma City, OK 73116
Result: (Sheet 2):
Cell A1: A. E. Ewell Investment Co. Cell B1: P.O. Box 27 Cell C1: Ardmore, OK 73402
Cell A2: Aimie A. Akers, Trustee of the Howard A. and Aimie A. Akers Revocable Joint Trust Agreement dated 5/03/1996 Cell B2: 11 Nichols Road Cell C2:Luray, VA 22835
Cell A3: Alison Evans Taylor and James Andrew Taylor Cell B3: 1523 Glenwood Avenue Cell C3: Oklahoma City, OK 73116
I know this is very specific and there needs to be rules in place, but I just need the base code and I'll implement the rules.

Related

If a cell's value is found on another column, how to return the cell's value from another column which is on same row with the synced cell?

My Excel table is looking like this.
A column is the one that I want to fill in with correct data.
B column is where the lookup values are.
C column is the one where I want to extract data from.
D column is where data from B column will be searched.
For example, if data from B2 is found on D7 cell, I want to have in A2 the value from C7.
My Countries///My Codes////All Countries//////All Codes
AD Afghanistan AF
AU Albania AL
Algeria DZ
American Samoa AS
Andorra AD
Angola AO
Anguilla AI
Antarctica AQ
Antigua and Barbuda AG
Argentina AR
Armenia AM
Aruba AW
Australia AU
Austria AT
Azerbaijan AZ
It would be much appreciated your help because I would like to learn as much as I can about excel formulas.
Kind Regards,
Ioan
In A1 enter:
=INDEX(C$1:C$15,MATCH(B1,D$1:D$15,0))
and copy down:
Note:
MATCH() finds the row.INDEX() grabs the value.
Chris is right, looks like you need a vlookup, example
B1 would be
=Vlookup(A1,c1:d200,2,0)
B2 would be
=Vlookup(A2,c1:d200,2,0)
And so on
It works like this
Vlookup (value to lookup, range the lookup and return values are in, column number from range you want to return, exact match only (0 or false))
Though Chris's link is more detailed

Sum Multiple values in different Rows using Vlookup Function

A B
France 152
Italy 255
France 221
Spain 215
USA 222
Spain 155
I desire to add each value occurring in front of repeating countries using Vlookup function
Solution:
A B
France 373
Spain 370
If you use a SUMIF then you can total the columns
If the data starts in cell A1 then in cell C2 type
=SUMIF(A:A,A3,B:B)
then drag the formula down. this will give totals for each country
Or if you just want to show the first instance (where it says France for example) then use
=IF(COUNTIF(A$1:A2,A2)=1,SUMIF(A:A,A2,B:B),"")
You won't be able to do it with a vlookup.
You could use a pivot table which might be easier and that is useful for this exact type of question.
To get the list of repeating countries enter the following formula in Cell D2
=IFERROR(INDEX($A$2:$A$7,MATCH(1,INDEX((COUNTIF($D$1:D1,$A$2:$A$7)=0)*(COUNTIF($A$2:$A$7,$A$2:$A$7)>1),0,0),0)),"")
Then to get sum of corresponding country, in Cell E2 enter
=SUMIF($A$2:$A$7,D2,$B$2:$B$7)
Drag/Copy formulas as required. See image for reference.

If Cell Contains XXX Then Return Corresponding Value

A B C D
1 Ross Sales John Guys Finance
2 Smith Sales Sam Andy #N/A or False
3 Guys Finance Mike Ross Sales
I'm putting this formula in cell "D1" but it's not giving me correct result
=IF(SUMPRODUCT(--ISNUMBER(SEARCH(A:A,C:C)))>0,B:B)
INDEX MATCH function would not work because it's not exact value
What can I put in "D1" and down to give me result as in the table above?
Try this in D2,
=LOOKUP(1E+99, SEARCH(A2, C:C), B:B)
'or cut down the full column references
=LOOKUP(1E+99, SEARCH(A2, C$2:C$4), B$2:B$4)
'alternately as a wildcard MATCH
=INDEX(B:B, MATCH("*"&A2&"*",C:C, 0))
Fill down as necessary.
      

Excel Index Partial match

I have Sheet1 with column A listing every single country in alphabetical order..
A
1 Afghanistan<
2 Albania
3 Algeria
4 American Samoa
5 Andorra
----------
228 United Kingdom
229 United States
etc
I have Sheet2 column A with empty cells with adjacent cells in column B listing address details
A B
1 empty cell Unit 3, Road;London, United Kingdom
2 empty cell Building 1, Road, TX, United States
3 empty cell 8th floor, Business Park, India 1234
etc
What I would like to know is how can I obtain the country within the address details in sheet2 column B and place them in Sheet2 column A, based on a match on the list of countries in Sheet1 column A.
Part of the problem is there is no coherent method as to how to country is placed within the address; could be at the end or in the middle of the address.
I have tried various index match formulas with no luck
any help would be appreciated.
I tried it with the reference table being in A1:B7, and lookups being A10:B10 onwards down. The formula is for these cells. You can adjust it for Sheet1/2!.
Assuming your data is in B10 onwards, and your reference data was in B1:B7, you can write this formula in A10 =INDEX($B$1:$B$7,MAX(IF(ISERROR(FIND($B$1:$B$7,B10)),-1,1)*(ROW($B$1:$B$7)-ROW($B$1)+1))). This is an array formula, so please hit Ctrl+Shift+Enter for excel to read it as an array formula.
(In the screenshot, I have pasted the table in A10:B12 as values only in D10:E12)
Text to Columns with a comma delimiter

Excel - Multiline Textbox offset each line onto the next column?

I need some Excel help here.
I am trying to create a database to store customers information in my shop.
The customer will have a name and address, something like this:
MR SMITH
123 FLAT A, 321 ROAD,
LONDON,
AB12 3AB
UNITED KINGDOM
This address has 5 rows. I want to just copy and paste everything into my userform which has a Multiline Textbox. I need it to offset each row into each column of my spreadsheet.
So it ends up looking like this:
CELL A1 = MR SMITH
CELL B1 = 123 FLAT A, 321 ROAD,
CELL C1 = LONDON,
CELL D1 = AB12 3AB
CELL E1 = UNITED KINGDOM
I know I can create a 5 single line Textboxes in my userform, but I want to save time by copying everything into 1 Textbox instead of 5.
Please help.
Thanks!
The data I have stored in the cell H5, but you can use a Var or a Textbox like source...
If you want to save in the cells, use:
Range("A1:E1").Value = Split(Range("H5").Value, Chr(10))
if you want an array to manipulate (put value in separate Textbox), use
myarr = Split(Range("H5").Value, Chr(10))

Resources