Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Stefi.
Your code works perfectly, and it has also helped me understand a lot more about how macro code can be structured. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VLookup Method for Comma Delimited Field | Excel Discussion (Misc queries) | |||
looping through comma delimited text | Excel Programming | |||
Japanese text lost when save as tab delimited text file | Excel Programming | |||
Converting Tab Delimited Text File to A Comma Delimited Text File | Excel Programming | |||
How to read text from a non-delimited text file? | Excel Programming |