Excel non-uniform data extraction - excel

I've had a really hard time tracking down a solution for this--though I'm sure it's out there. Just not sure of the exact wording to get what I'm looking for.
I have a huge data set where some of the data is missing information so it is not uniform. I want to extract just the name into one column and the e-mail in to the next column.
The best way I can narrow this down is there is a space between each unique entry with the name always being in the first box.
Example:
John Doe
John Doe's Company
(555) 555-5555
John.doe#johndoe.com
John Doe
(555) 555-5555
John Doe
Jane Doe's Company
John.doe#johndoe.com
With the results wanted being (in two excel columns):
John Doe | john.doe#johndoe.com
John Doe |
John Doe | john.doe#johndoe.com
Any suggestions on the best way to do this would be appreciated it. To make it complicated if there was no e-mail I would want to ignore that set completely, but I could just manually check.

VBA coding:
1. Indicate in Row1 the initial row where the data begins.
2. Place a flag in this case the word "end" to indicate the end of the information.
3. Create a second sheet
Sub ToList()
Row1 = 1 'Row initial from data
Row2 = 1 'Row initial to put list
Do
Name = False
Do
field = Trim(Sheets(1).Cells(Row1, 1))
If field <> "" And LCase(field) <> "end" And Not Name Then
Sheets(2).Cells(Row2, 1) = field
Name = True
End If
Row1 = Row1 + 1
Loop Until (IIf(field = "" Or LCase(field) = "end", True, False))
fieldprev = Sheets(1).Cells(Row1 - 2, 1)
If InStr(fieldprev, "#") > 0 Then
Sheets(2).Cells(Row2, 2) = fieldprev
End If
Row2 = Row2 + 1
Loop Until (IIf(LCase(field) = "end", True, False))
End Sub

Extracting the e-mail address shouldn't be too difficult as you just need to is search for a string containing the # character. A series of search() and mid() functions can be used to separate out the individual words. Search for each instance of a space and use that value in a mid() function. Then search for # in the results and you should find the e-mail address. Extracting the name will be more difficult if the original data is very messy.
However I second the comment above about using an external script, especially for a large dataset. Excel isn't really designed for the sort of thing you are describing here.

Related

VBscript to get total count of unique values in spreadsheet

UPDATED with questions still:
So I've used count before and haven't had issue. However I am trying to get a total for each unique value in a spreadsheet. I'm using vb script because I need this to be outside of excel for several reasons.
So if my data is like :
Bob
Bob
Ted
Ann
Ann
I'm looking for the results to be
Bob =2
Ted = 1
Ann = 2
etc...
This is what I have so far, which gets me my unique count but not a total for the unique items...
Dim objDict,item,arr,cRow, result,count
Set objDict = CreateObject("Scripting.Dictionary")
arr= .Sheets(1).Range("A2:A" & iLastRow )
For Each key In arr
If key <>"" Then
If Not objDict.Exists(key) Then objDict.Add key, Nothing
else
objDict.key("name").Item = objDict.Item() + 1
end if
End If
Next
I've updated with Marks suggestion, yet I continue to get hung up on key.
I'm not understanding how to use in this situation. From the help file Mark supplied, the example is adding a key and an item. I'm just adding keys, so what am I missing here?
Thanks for any help in this. Just pointers in the right direction are most welcome.

Excel - Use Named Range to Find and Copy Found Words to Adjacent Cell

I have a long list of sentences, and a long list of words that I need to identify in each sentence.
Sentences
Jack goes to the party with Jill.
Jill likes Paul, but he doesn't know she exists.
Jill went to party with Jack to make Paul jealous.
Jill fell down and broke her crown.
Jack came tumbling after Jill because he is infatuated with her.
Named Range Words
to
the
party
well
let's say there are over 100 words in the named range.
Output would be
Sentences Words
Jack goes to the party with Jill. to, the, party
Jill likes Paul, but he doesn't know she exists.
Jill went to party with Jack to make Paul jealous. to, party
Any help is GREATLY appreciated!~
Would a user defined function like this work?
Function COMBINETEXT(Sentence_Range As Range, Key_Range As Range)
Dim c As Range
Dim output As String
‘output = Sentence_Range & " "
For Each c In Key_Range.Cells
On Error GoTo errorHandler
If Application.WorksheetFunction.Search(c.Value, Sentence_Range) > 0 Then output = output & "/" & c.Value
errorHandler:
Next c
output = right(output,len(output) -1) ‘Will get rid of first /
COMBINETEXT = output
End Function

Need formula for excel, to subtract the number "9" to each number individually and

I want you to have some fun. I need something specific.
First i must explain what i do. I use a simple codification for product prices at retail store, because i dont want people know the real price for themselves. So i change the original numbers to another subtracting the number 9 for each number.
Normally I manually write down all the prices with this codification for every product.
So.. for example number 10 would be 89. (9-1 = 8) and (9-0 = 9)
Other examples:
$128 = 871
$75 = 24
$236 = 763
$9 = 0
Finally i put 2 number nines (9) at the beginning of the codified price also, to confuse people who might think that number could be the price.
So the examples i used before are like this:
99871 (means $128)
9924 (means $75)
99763 (means $236)
990 (means $9)
Remember that i need 2 (two) nines before the real price. The real prices never start with 0 so, the nines at the beginning exist only to confuse people.
Ok. So, now that you understand, here comes the 2nd part.
I have an excel whith hundreds of my products added, with prices, description, etc. And i decided it is time to use a printer and start to print this information from excel. I have a software to do that, but first i need to have the codified prices in the excel also.
The fun part begins when i want to convert the real prices that are already written in my excel document into a new column AUTOMATICALLY. So that way i don´t have to type again all the prices in codified form for the old and new items i add in the future.
Can someone help me with this? Is it even possible?
I tried with =A1-9999 but, it works well with 2 character number only. Because if the real price is 5, i will get 3 nines: 9994(code). And if the price is 234 i will get only 1 nine 9765(code). And it is a condition i need to have the TWO nines at first.
Thank you very much in advanced!
Though you have requested for formula , I am suggesting VBA program which seems to me very convenient.
You have to open VBE and insert a module and copy the program. Change the code lines wherever indicated to suit your requirements for sheets etc.
Sub NumberCode()
Dim c As Range
Dim LR As Integer
Dim numProbs As Long
Dim sht As Worksheet
Dim s As Integer
Dim v As Long
Dim v1 As Long
Set sht = Worksheets("Sheet1") ' change as per yr requirement
numProbs = 0
LR = sht.Cells(Rows.Count, "A").End(xlUp).Row
For Each c In sht.Range("A1:A" & LR).Cells
s = Len(c)
v = c.Value
v1 = 99
For s = 1 To Len(c)
v1 = v1 & (9 - Mid(c, s, 1))
Next
c.Offset(0, 1).Value = v1
v1 = 99
numProbs = numProbs + 1
Next
MsgBox "Number coding finished"
End Sub
Sample sheet of results is appended below.
I will be using helper cells but you could dump it all into one cell if you want since you are only dealing with 4 characters.
For the purpose of this example, I am assuming your original price list starts in B11.
=IFERROR(9-MID($B11,COLUMN(A1),1),"")
Place that in D11 and copy to the right three more times so you have it from D11 to G11. That formula strips off 1 character from your price and subtracts that character from 9. When you go the next column it repeats itself. If you do not have that many characters, it will return "".
In C11 you will build your number based on the adjacent 4 columns using this formula:
="99"&D11&E11&F11&G11
It places 99 in front then adds the numbers from the adjacent 4 columns.
Select cells C11 to G11 and copy and paste downward beside your data column as far as you need to go.
An alternate more concise method would be:
=REPT(9,LEN(B11)+2)-B11
Perhaps I'm missing something, though simply:
=REPT(9,2+LEN(A1))-A1
seems good to me.
Regards

Compare data in two cells to look for a partial match

This is probably quite a simple script to write, but my coding is terrible.
I have a column with A list of surnames, and column B with file names that should contain the surname somewhere in the string.
i.e.
A B
Smith 10 0950 Smith 10101950
Jones 10 0955 Jones 10051942
Thomas 10 1008 Thoma 01051972
I need to check that the spelling of the surname in column A is found within the string in column B, and highlight the row where there is a mismatch.
In this instance the third line for Thomas would be highlighted.
There should be no more than 1000 rows to be checked.
I cannot find a piece of code anywhere that will do this for me.
Thanks for any assistance you can offer.
dim numrows as long
numrows = Cells.find("*", [A1], , , xlByRows, xlPrevious).Row
'loop over all rows
for i = 1 to numrows
'instr function returns 0 if string 2 is not found within string 1. in this case, if the value in col A, is not found within col B
if instr(1, cells(i,2).formulaR1C1, Cells(i,1).formulaR1C1) = 0 then
Cells(i,1).entireRow.interior.color = RGB(255,255,0) 'highlight row
end if
next
Welcome to SO, you're correct, it was simple. however please do note that according to the help page on "on topic answers" - "Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results." do keep that in mind in future posts :)
also, don't forget to mark as answer if this works for you :)

VBA HasNextCell function

I have tried searching for a solution but cant find it.
I have a list of products, and each product has many parts. Is there a HasNext function in VBA to see if there are more parts for a product? For instance, for chicken burger, I want to pick out all the parts, put them in an array and display it in another sheet.
I cant hard-code the array, because the client would add in more products in the future. There might be 15, 20, 23 parts etc. Is there a HasNext function to get the value in the next column and add it into the array?
Product | Part 1 | Part 2 | Part 3
Chicken Burger | Veggie | Bun | Patty
You can use Range.End property to detect how "long" the title row is:
Dim col
col=Range("A1").End(xlToRight).Column
For i = 1 to col
If Cells(1, col).Value <> "" Then
'...
End
P.S. I wonder why MSDN refers to it as "property" instead of "method"...

Resources