Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard mouse network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Excel macro to separate entries in a single cell

Reply  
Thread Tools
mrincognito's Avatar
Junior Member with 7 posts.
 
Join Date: Jun 2009
05-Jun-2009, 11:56 AM #1
Solved: Excel macro to separate entries in a single cell
Hello,

I have 2 data sheets in an Excel workbook that have ~8000 rows of data each. Each row has 2 columns. Col A is an entity ID and Col B contains a set of long string values (i.e., institutional affiliation and location), each value separated by a semicolon (. More specifically, Col A is a paper ID#, Col B includes the institutional affiliations for each author.

What I need to do is to take the distinct values in Col B and separate them into individual rows for data processing. Also, when I separate the values, I need to retain the relationship between the values in Col B and Col A. That is, I need to put each institutional affiliation in its own row, but ensure that the relationship to the paper remains intact. Put another way, I want to cut everything that follows a ; in Col B, insert a row, paste what I cut into the next row in Col B, and then go back up one row, over one cell, copy the unique ID, go down one cell, and paste.

So here is my problem: when I execute the find function in Excel 2008 and search for the semicolon, it returns the entire cell. Normally, if one executes a find command, it highlights the character. The next logical step would be a shift+end to highlight the remainder of the text to the end of the line. This does not work because the find command returns the entire cell. Does anyone have any advice on how to fix this? Right now I am thinking I need to export the data into another program, execute the find and replace, and then re-import the data. I would rather find a more elegant solution to the problem.

-MrInc



Here
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
05-Jun-2009, 12:47 PM #2
First, welcome to the Forum!!!
Give me some fake data and I will mess with a solution.
bomb #21's Avatar
Distinguished Member with 8,082 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
05-Jun-2009, 12:50 PM #3
You have Mac?
mrincognito's Avatar
Junior Member with 7 posts.
 
Join Date: Jun 2009
05-Jun-2009, 01:01 PM #4
See attached file. The data are publicly available, so there are no concerns re: privacy. Thank you for the help.

Yes, I do have a mac. However, I will be doing most of my work on my desktop, which is a Windows machine.
Attached Files
File Type: xls datasample.xls (20.5 KB, 167 views)
bomb #21's Avatar
Distinguished Member with 8,082 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
05-Jun-2009, 01:05 PM #5
Quote:
Originally Posted by mrincognito
See attached file. The data are publicly available, so there are no concerns re: privacy. Thank you for the help.

Yes, I do have a mac. However, I will be doing most of my work on my desktop, which is a Windows machine.
Yeah, that was directed at slurpee.

Who will now provide your solution.
bomb #21's Avatar
Distinguished Member with 8,082 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
05-Jun-2009, 01:54 PM #6
My bad, slurpee's busy.

Tried this on your sample, ran OK.

Make sure your actual data's backed up before you try it on that.

Sub test()
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Output").Delete
Application.DisplayAlerts = True
Home = ActiveSheet.Name
Sheets.Add
ActiveSheet.Name = "Output"
Range("A1") = "ISI": Range("B1") = "Other"
Sheets(Home).Select
LastRow = Range("B" & Rows.Count).End(xlUp).Row
For Each Cell In Range("B1:B" & LastRow)
x = Len(Cell) - Len(Replace(Cell, ";", "")) + 1
Sheets("Output").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(x) = Cell.Offset(, -1)
AllAdds = Cell & ";"
For i = 1 To x
ThisAdd = Left(AllAdds, InStr(AllAdds, ";") - 1)
Sheets("Output").Range("B" & Rows.Count).End(xlUp).Offset(1) = _
WorksheetFunction.Trim(ThisAdd)
AllAdds = Mid(AllAdds, InStr(AllAdds, ";") + 1, 256)
Next i
Next Cell
Sheets("Output").Select
Columns.AutoFit
Application.ScreenUpdating = True
End Sub
__________________
"Love All The People."
Bill Hicks, 1961 - 1994 -- R.I.P.
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
05-Jun-2009, 02:04 PM #7
Dang, I just got back here! Nice work bomb!
Been listening to the news about more resignations in the UK Parliament....
Oh, and nope, Macs are nice, but too pricey for what I need a PC for.
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
05-Jun-2009, 02:13 PM #8
bomb, that went into my folder of useful little VBA codes - I could see using that quite a lot in the future. Thanks!!!!
bomb #21's Avatar
Distinguished Member with 8,082 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
05-Jun-2009, 02:13 PM #9
Yeah, the meeeja schadenfreude is in overdrive since ... weeks ago.

YW
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
05-Jun-2009, 03:18 PM #10
at first I thought you were referring to yourself...oh, the Parliament, yep....
It seems Canada is having some problems too - here in the US, well, we just assume that the politicians are largely crooks (well, actually, I tend to think they are more stupid than crooked) - Obama excepted!!
__________________
Iowa? I could have sworn this was heaven.
Well, I think I can answer this question most successfully in mime.
My theme song... | Affero - rate me!
mrincognito's Avatar
Junior Member with 7 posts.
 
Join Date: Jun 2009
05-Jun-2009, 03:50 PM #11
Thank you very much. This worked very well.
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
05-Jun-2009, 04:14 PM #12
mrincognito, please use the button at the top of the page to mark this thread as Solved.
See you around!
Reply

Tags
excel, macro help

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:17 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.