Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Looping through delimited text and using VLOOKUP

I am a bit stuck on this, as I am not a macro expert.

I have a worksheet with two columns. The first column holds the name of an
corporate email Distribution List (DL), the next column contains the members
belonging to the DL (with some additional detail). Each member cell can have
multiple names, delimited by New Line characters(LF, CHAR(10)).
e.g.
| A | B |
DL_Team1 Joe, Users, NZ
Fred, Users, AU
Jane, Users, NZ
DL_Team2 Bill, Users, NZ
Mary, Users, AU

On another worksheet I have a column of some selected team members to do a
VLOOKUP against, one member name per cell.
e.g.
| A |
Mary
Fred

How do I flag a DL if it contains any member from the team I am interested in?

Thanks. I really appreciate your help on this.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Looping through delimited text and using VLOOKUP

Try this macro:

Sub test()
Dim teamcell As Range, teamrng As Range
rowsno = Range("A" & Rows.Count).End(xlUp).Row
Set teamrng = Range("A1:A" & rowsno)
Range("C" & rowsno).ClearContents
For Each teamcell In teamrng
namearray = Split(Range("B" & teamcell.Row), Chr(10))
nameno = UBound(namearray, 1) + 1
For n = 0 To nameno - 1
commapos = InStr(1, namearray(n), ",")
membername = Left(namearray(n), commapos - 1)
selmember = True
On Error GoTo notfound
namepos = Sheets("Sheet2").Columns("A:A").Find(What:=membern ame,
After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Row
If selmember Then Exit For
Next n
If selmember Then Range("C" & teamcell.Row) = "First selected
member: " & membername
Next teamcell
Exit Sub
notfound:
selmember = False
Resume Next
End Sub

Regards,
Stefi

Cyberguy ezt *rta:

I am a bit stuck on this, as I am not a macro expert.

I have a worksheet with two columns. The first column holds the name of an
corporate email Distribution List (DL), the next column contains the members
belonging to the DL (with some additional detail). Each member cell can have
multiple names, delimited by New Line characters(LF, CHAR(10)).
e.g.
| A | B |
DL_Team1 Joe, Users, NZ
Fred, Users, AU
Jane, Users, NZ
DL_Team2 Bill, Users, NZ
Mary, Users, AU

On another worksheet I have a column of some selected team members to do a
VLOOKUP against, one member name per cell.
e.g.
| A |
Mary
Fred

How do I flag a DL if it contains any member from the team I am interested in?

Thanks. I really appreciate your help on this.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Looping through delimited text and using VLOOKUP

Thanks Stefi.

Your code works perfectly, and it has also helped me understand a lot more
about how macro code can be structured.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Looping through delimited text and using VLOOKUP

Here is my contribution back to the forum. I had trouble always replacing
semicolon delimiters with newline characters because the text was sometimes
too long for the formula. Here is my solution, loosely based on Stefi's
earlier code. Thanks Stefi for your really valuable help!!! :-)

' Put newline character (LF) in place of every "; " delimiter in text
' Useful when text is too long for regular search and replace
Sub Newline_At_Semicolon()
Dim Workcell As Range, Workrng As Range
rowsno = Range("B" & Rows.Count).End(xlUp).Row
Set Workrng = Range("B1:B" & rowsno)
Range("D" & rowsno).ClearContents
For Each Workcell In Workrng
namearray = Split(Range("B" & Workcell.Row), "; ")
nameno = UBound(namearray, 1) + 1
membername = namearray(0)
For n = 1 To nameno - 1
membername = membername & Chr(10) & namearray(n)
Next n
Range("D" & Workcell.Row) = membername
Next Workcell
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Looping through delimited text and using VLOOKUP

And just to show that I am paying attention in class, I spotted your
deliberate mistake ;-)

Sub test()
Dim teamcell As Range, teamrng As Range
rowsno = Range("A" & Rows.Count).End(xlUp).Row
Set teamrng = Range("A1:A" & rowsno)
Range("C" & rowsno).ClearContents


I think the 4th code line should read:
Range("C1:C" & rowsno).ClearContents




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Looping through delimited text and using VLOOKUP

You are right, my mistake!
You are welcome! Thanks for the feedback!
Stefi

Cyberguy ezt *rta:

And just to show that I am paying attention in class, I spotted your
deliberate mistake ;-)

Sub test()
Dim teamcell As Range, teamrng As Range
rowsno = Range("A" & Rows.Count).End(xlUp).Row
Set teamrng = Range("A1:A" & rowsno)
Range("C" & rowsno).ClearContents


I think the 4th code line should read:
Range("C1:C" & rowsno).ClearContents


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLookup Method for Comma Delimited Field DoveArrow Excel Discussion (Misc queries) 1 December 22nd 11 12:59 PM
looping through comma delimited text DZ Excel Programming 2 May 24th 08 05:08 AM
Japanese text lost when save as tab delimited text file Greg Lovern Excel Programming 0 October 24th 07 08:39 PM
Converting Tab Delimited Text File to A Comma Delimited Text File Dave Peterson Excel Programming 0 June 13th 07 03:13 PM
How to read text from a non-delimited text file? Phil Excel Programming 8 May 22nd 07 01:09 PM


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"