+ Reply to Thread
Results 1 to 25 of 25

Split contents of cell into single names then search for names on different sheet.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Split contents of cell into single names then search for names on different sheet.

    Good Morning All,

    I'm trying to write a macro to split the contents of a cell when the contents are separated by a semicolon ;

    This is for an automatic e-mail macro, the cell I'm trying to split contains the names of people previously e-mailed, like so. Bob Johnson; Michael Faraday

    I'd like to split the names up and then search each name on another sheet and return their e-mail address.

    I found the below, which splits the contents of cells into more cells.

    http://www.excelforum.com/excel-prog...-at-every.html

    Any help or advice would be greatly appreciated.

    R

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Split contents of cell into single names then search for names on different sheet.

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    I've uploaded a stripped down version of my workbook with and example put into it. The workbook needs to be within that folder for all the macros to work correctly.

    If you have a look at the programming you'll see that there are a couple of e-mail macros. The auto mail sub works great, and does everything I want to be able to do when I only have one contact to deal with. But if I have more than one contact then I'm unsure who I'd go about it. If you add a second contact to the contacts list, and select data on the transmittal sheet tab. choose both contacts and the example document then click print to pdf. it will log the data in the next tab - transmittal register. its using this information that I send automatic reminder e-mails. I want to be able to split the distribution coloumn into the names and then search those names on the contacts sheet to return the address for each person mailed to.

    I'm sorry it's all very difficult to explain because I've added so many different functions to this workbook and they all tie in with each other. If you have any other questions I'd be more than happy to help and I'm very greatful for your response.

    R
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    Hi,

    Is splitting the cell contents an issue ?
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  5. #5
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    It's not an issue when I e-mail internally within my company, because you can write a name in the to: field and it will pick up the address from the saved contacts, which was why I separated multiple contacts with ; anyway. However I've found I can't save external contacts in my outlook under names like this so it would have to fetch their e-mail address from the contacts list. I could possible split the cell and save each name into a different cell/row. look up the e-mails for each row of contact names, compile them into a string of e-mail addresses separated by ; and then clear those cells of the list? I'm not really sure of the best way to go about this
    Last edited by RichTea88; 12-17-2013 at 07:25 AM.

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    Try this,

    Function get_email_id(email_name As String) As String
    'code by xlbiznes
    Dim email_db(3, 1) As String ' 2 dimensional array to hold name and email id
    
    email_db(0, 0) = "test1"
    email_db(0, 1) = "[email protected]"
    email_db(1, 0) = "test2"
    email_db(1, 1) = "[email protected]"
    email_db(2, 0) = "test3"
    email_db(2, 1) = "[email protected]"
    email_id = "*"
    
    For x = 0 To UBound(email_db)
    
    If email_db(x, 0) = email_name Then ' if found return the email id
    get_email_id = email_db(x, 1)
    End If
    Next
    
    End Function

  7. #7
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    Xlbiznes, Thanks for your help.

    I'm a bit confused by your code, where should I put it and how does it work?

  8. #8
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    Okay, I've looked over arrays a bit more and I understand what you're going for. Maybe if I give you a bit more details you can help me shape the above into a working function?

    The distribution list is stored on sheet 'Transmittal Register' in column F. It will read something like this "Adam Woods; Paul Findlay; John Tyler"

    The contact details for these people is found on sheet 'Contacts', Their full names e.g 'Adam Woods' is found in column K and their e-mail address is found in column C

    As you can see in the below sub to create an automatic e-mail the 'To:' field in the e-mail is just the contents of Column F, but I'd like to make it split the names up and collect their e-mail addresses from contacts then use thi for the 'To:' field instead

    Sub SendEMail()
        Dim Email As String, SubJ As String
        Dim Msg As String, URL As String
        Dim DocT As String
        Dim LastRow As Long, NextRow As Long, RowNo As Long
        Dim wsEmail As Worksheet
        Dim Attach As String
        Dim OutApp As Object
        Dim OutMail As Object
        Dim bng As Range
        Dim FPath As String
        Dim Ease As String
        Dim FName As String
    
        Set wsEmail = ThisWorkbook.Sheets("Transmittal Register")
        
        With wsEmail
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    
            For RowNo = 2 To LastRow
                'Change "Date + 1" to suit your timescale
                
                If .Cells(RowNo, "L") = "" And .Cells(RowNo, "I") <= Date + 1 Then
                    
                    On Error Resume Next
                    Set OutApp = GetObject("Outlook.Application")
                        On Error GoTo 0
                        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                        Do: Loop Until Not OutApp Is Nothing
                    Set OutMail = OutApp.CreateItem(0)
                    Set bng = wsEmail.Cells(RowNo, "A")
                    FPath = Application.ActiveWorkbook.Path
                    FName = bng.Hyperlinks(1).Address
                    Ease = FPath & "\" & FName
                    With OutMail
                        Email = wsEmail.Cells(RowNo, "F")
                        DocT = wsEmail.Cells(RowNo, "D")
                        SubJ = "Automated E-mail - Document Due " & wsEmail.Cells(RowNo, "I")
                        Msg = ""
                        
                        Msg = "Good Day" & "," & vbCrLf & vbCrLf _
                            & "This is an automated e-mail to let you know that document" & vbCrLf _
                            & wsEmail.Cells(RowNo, "C") & " - " & DocT & vbCrLf _
                            & "That was issued for " & wsEmail.Cells(RowNo, "G") & " is due on " & wsEmail.Cells(RowNo, "I") & "." & vbCrLf & vbCrLf _
                            & "Many Thanks, " & vbCrLf & vbCrLf & "AutoMech"
                            
                        .To = Email
                        .CC = ""
                        .SentOnBehalfOfName = "PPU Document Control"
                        .Subject = SubJ
                        .ReadReceiptRequested = False
                        .Body = Msg
                        .Attachments.Add (Ease)
                        .Display
    
                    End With
                Set OutApp = Nothing
                Set OutMail = Nothing
                Set bng = Nothing
                .Cells(RowNo, "L") = "RS"
                .Cells(RowNo, "Q") = Date
            End If
            
            If .Cells(RowNo, "L") = "RS" And .Cells(RowNo, "Q") <= Date - 3 And .Cells(RowNo, "Q") <> "" Then
            .Cells(RowNo, "Q") = Date
             On Error Resume Next
                    Set OutApp = GetObject("Outlook.Application")
                        On Error GoTo 0
                        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                        Do: Loop Until Not OutApp Is Nothing
                    Set OutMail = OutApp.CreateItem(0)
                    Set bng = wsEmail.Cells(RowNo, "A")
                    FPath = Application.ActiveWorkbook.Path
                    FName = bng.Hyperlinks(1).Address
                    Ease = FPath & "\" & FName
                    With OutMail
                        Email = wsEmail.Cells(RowNo, "F")
                        DocT = wsEmail.Cells(RowNo, "D")
                        SubJ = "Automated E-mail - Document Due " & wsEmail.Cells(RowNo, "I")
                        Msg = ""
                        
                        Msg = "Good Day" & "," & vbCrLf & vbCrLf _
                            & "This is an automated e-mail to let you know that document" & vbCrLf _
                            & wsEmail.Cells(RowNo, "C") & " - " & DocT & vbCrLf _
                            & "That was issued for " & wsEmail.Cells(RowNo, "G") & " is due on " & wsEmail.Cells(RowNo, "I") & "." & vbCrLf & vbCrLf _
                            & "Many Thanks, " & vbCrLf & vbCrLf & "AutoMech"
                            
                        .To = Email
                        .CC = ""
                        .SentOnBehalfOfName = "PPU Document Control"
                        .Subject = SubJ
                        .ReadReceiptRequested = False
                        .Body = Msg
                        .Attachments.Add (Ease)
                        .Display
    
                    End With
                Set OutApp = Nothing
                Set OutMail = Nothing
                Set bng = Nothing
                .Cells(RowNo, "L") = "RS"
            End If
         Next
        End With
    End Sub

  9. #9
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    Hi,

    try this in your code :
    'code by xlbiznes
    Dim a() As String
    Dim email As String
    
    a = Split(wsEmail.Cells(RowNo, "F"), ";")
    
    For x = 0 To UBound(a)
    
    email = email & Sheets("contacts").Range("c" & Application.WorksheetFunction.Match(a(0), Sheets("Contacts").Range("K:K"), 0)) & ","
    
    Next
    
    email = Left(email, Len(email) - 1)
    
    MsgBox email

  10. #10
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    Thanks again for persevering bud,

    We're almost there! It works fine when I have only one contact, but when I have more than one. It does determine that I have more, but when it collects the e-mail address from the contacts, itjust gets the first e-mail address and repeats that 3 times. Then I get an error when trying to display the e-mail for some reason.

  11. #11
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    Oops.

    Replace :

    email = email & Sheets("contacts").Range("c" & Application.WorksheetFunction.Match(a(0), Sheets("Contacts").Range("K:K"), 0)) & ","
    with

    email = email & Sheets("contacts").Range("c" & Application.WorksheetFunction.Match(a(x), Sheets("Contacts").Range("K:K"), 0)) & ","

  12. #12
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    if I change it to this
    email = email & Sheets("contacts").Range("c" & Application.WorksheetFunction.Match(a(x), Sheets("Contacts").Range("K:K"), -1)) & ","
    it gets a little further and I get this '[email protected]; [email protected]; [email protected]' so it's skipped the second e-mail and returned the third example twice

  13. #13
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    Hey dude,

    I gave that a try when I got the first error, but to no avail either. Though when I get the error it's that line that gets highlighted. If i hover over email its "[email protected]," and if I hover over a(x) it equals 'Example Two'. Which is the second name I put in to test it, so thats correct. So I'm unsure why it's not working from there on.

  14. #14
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    It gives me all the 3 email ids, when i simulate the code, can you check your contacts sheet.

  15. #15
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    Hmmm, are you using -1 instead of 0? I gave it a look over but everything is in order.

  16. #16
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    I am using 0 in the match condition.

  17. #17
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    It just occurred to me that I may have just put it into my sub wrong, so here's how I've input it

    Sub SendEMail()
        Dim email As String, SubJ As String
        Dim Msg As String, URL As String
        Dim DocT As String
        Dim LastRow As Long, NextRow As Long, RowNo As Long
        Dim wsEmail As Worksheet
        Dim Attach As String
        Dim OutApp As Object
        Dim OutMail As Object
        Dim bng As Range
        Dim FPath As String
        Dim Ease As String
        Dim FName As String
        Dim a() As String
    
        Set wsEmail = ThisWorkbook.Sheets("Transmittal Register")
        
        With wsEmail
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    
            For RowNo = 2 To LastRow
                'Change "Date + 1" to suit your timescale
                
                If .Cells(RowNo, "L") = "" And .Cells(RowNo, "I") <= Date + 1 Then
                    
                    On Error Resume Next
                    Set OutApp = GetObject("Outlook.Application")
                        On Error GoTo 0
                        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                        Do: Loop Until Not OutApp Is Nothing
                    Set OutMail = OutApp.CreateItem(0)
                    Set bng = wsEmail.Cells(RowNo, "A")
                    FPath = Application.ActiveWorkbook.Path
                    FName = bng.Hyperlinks(1).Address
                    Ease = FPath & "\" & FName
                    
                    a = Split(wsEmail.Cells(RowNo, "F"), ";")
                    For x = LBound(a) To UBound(a)
                        email = email & Sheets("contacts").Range("c" & Application.WorksheetFunction.Match(a(x), Sheets("Contacts").Range("K:K"), -1)) & "; "
                    Next x
                    email = Left(email, Len(email) - 1)
                    MsgBox email
                    
                    With OutMail
                        DocT = wsEmail.Cells(RowNo, "D")
                        SubJ = "Automated E-mail - Document Due " & wsEmail.Cells(RowNo, "I")
                        Msg = ""
                        
                        Msg = "Good Day" & "," & vbCrLf & vbCrLf _
                            & "This is an automated e-mail to let you know that document" & vbCrLf _
                            & wsEmail.Cells(RowNo, "C") & " - " & DocT & vbCrLf _
                            & "That was issued for " & wsEmail.Cells(RowNo, "G") & " is due on " & wsEmail.Cells(RowNo, "I") & "." & vbCrLf & vbCrLf _
                            & "Many Thanks, " & vbCrLf & vbCrLf & "AutoMech"
                            
                        .To = email
                        .CC = ""
                        .SentOnBehalfOfName = "PPU Document Control"
                        .Subject = SubJ
                        .ReadReceiptRequested = False
                        .Body = Msg
                        .Attachments.Add (Ease)
                        .Display
    
                    End With
                Set OutApp = Nothing
                Set OutMail = Nothing
                Set bng = Nothing
                .Cells(RowNo, "Q") = Date
    
    
                
            End If
            
            If .Cells(RowNo, "L") = "RS" And .Cells(RowNo, "Q") <= Date - 3 And .Cells(RowNo, "Q") <> "" Then
            .Cells(RowNo, "Q") = Date
             On Error Resume Next
                    Set OutApp = GetObject("Outlook.Application")
                        On Error GoTo 0
                        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                        Do: Loop Until Not OutApp Is Nothing
                    Set OutMail = OutApp.CreateItem(0)
                    Set bng = wsEmail.Cells(RowNo, "A")
                    FPath = Application.ActiveWorkbook.Path
                    FName = bng.Hyperlinks(1).Address
                    Ease = FPath & "\" & FName
                    With OutMail
                        email = wsEmail.Cells(RowNo, "F")
                        DocT = wsEmail.Cells(RowNo, "D")
                        SubJ = "Automated E-mail - Document Due " & wsEmail.Cells(RowNo, "I")
                        Msg = ""
                        
                        Msg = "Good Day" & "," & vbCrLf & vbCrLf _
                            & "This is an automated e-mail to let you know that document" & vbCrLf _
                            & wsEmail.Cells(RowNo, "C") & " - " & DocT & vbCrLf _
                            & "That was issued for " & wsEmail.Cells(RowNo, "G") & " is due on " & wsEmail.Cells(RowNo, "I") & "." & vbCrLf & vbCrLf _
                            & "Many Thanks, " & vbCrLf & vbCrLf & "AutoMech"
                            
                        .To = email
                        .CC = ""
                        .SentOnBehalfOfName = "PPU Document Control"
                        .Subject = SubJ
                        .ReadReceiptRequested = False
                        .Body = Msg
                        .Attachments.Add (Ease)
                        .Display
    
                    End With
                Set OutApp = Nothing
                Set OutMail = Nothing
                Set bng = Nothing
                .Cells(RowNo, "L") = "RS"
            End If
         Next
        End With
    End Sub

  18. #18
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    In your code :

     For x = LBound(a) To UBound(a)
                       email = email & Sheets("contacts").Range("c" & Application.WorksheetFunction.Match(a(x), Sheets("Contacts").Range("K:K"), -1)) & "; "
                    Next x
    You are using -1 that is greater than, if you use 0 it would be exact match. Can you try changing that to 0 and check the output.

  19. #19
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    When I change it back to 0 I just get an error saying:
    Run-time error '1004':
    "Unable to get the Match Property of the WorksheetFunction class"

  20. #20
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    I think this should work, I have remove the match function and added a range search.

    Sub SendEMail()
        Dim email As String, SubJ As String
        Dim Msg As String, URL As String
        Dim DocT As String
        Dim LastRow As Long, NextRow As Long, RowNo As Long
        Dim wsEmail As Worksheet
        Dim Attach As String
        Dim OutApp As Object
        Dim OutMail As Object
        Dim bng As Range
        Dim FPath As String
        Dim Ease As String
        Dim FName As String
        Dim a() As String
    
        Set wsEmail = ThisWorkbook.Sheets("Transmittal Register")
        
        With wsEmail
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    
            For RowNo = 2 To LastRow
                'Change "Date + 1" to suit your timescale
                
                If .Cells(RowNo, "L") = "" And .Cells(RowNo, "I") <= Date + 1 Then
                    
                    On Error Resume Next
                    Set OutApp = GetObject("Outlook.Application")
                        On Error GoTo 0
                        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                        Do: Loop Until Not OutApp Is Nothing
                    Set OutMail = OutApp.CreateItem(0)
                    Set bng = wsEmail.Cells(RowNo, "A")
                    FPath = Application.ActiveWorkbook.Path
                    FName = bng.Hyperlinks(1).Address
                    Ease = FPath & "\" & FName
                    
                    'code added
                    Dim c_rng As Range
                    Dim f_rng As Range
                    Set c_rng = Sheets("contacts").UsedRange
                    'new code ends
                    
                    
                    a = Split(wsEmail.Cells(RowNo, "F"), ";")
                    For x = LBound(a) To UBound(a)
                          'code added
                          Set f_rng = c_rng.Find(a(x), LookIn:=xlValues)
                          If f_rng Is Nothing Then getrow = 0 Else getrow = f_rng.Row
                        
                          If getrow > 0 Then
                          email = Sheets("contacts").Range("C" & getrow) & ","
                          End If
                          'code ends
                    Next x
                    email = Left(email, Len(email) - 1)
                    MsgBox email
                    
                    With OutMail
                        DocT = wsEmail.Cells(RowNo, "D")
                        SubJ = "Automated E-mail - Document Due " & wsEmail.Cells(RowNo, "I")
                        Msg = ""
                        
                        Msg = "Good Day" & "," & vbCrLf & vbCrLf _
                            & "This is an automated e-mail to let you know that document" & vbCrLf _
                            & wsEmail.Cells(RowNo, "C") & " - " & DocT & vbCrLf _
                            & "That was issued for " & wsEmail.Cells(RowNo, "G") & " is due on " & wsEmail.Cells(RowNo, "I") & "." & vbCrLf & vbCrLf _
                            & "Many Thanks, " & vbCrLf & vbCrLf & "AutoMech"
                            
                        .To = email
                        .CC = ""
                        .SentOnBehalfOfName = "PPU Document Control"
                        .Subject = SubJ
                        .ReadReceiptRequested = False
                        .Body = Msg
                        .Attachments.Add (Ease)
                        .Display
    
                    End With
                Set OutApp = Nothing
                Set OutMail = Nothing
                Set bng = Nothing
                .Cells(RowNo, "Q") = Date
    
    
                
            End If
            
            If .Cells(RowNo, "L") = "RS" And .Cells(RowNo, "Q") <= Date - 3 And .Cells(RowNo, "Q") <> "" Then
            .Cells(RowNo, "Q") = Date
             On Error Resume Next
                    Set OutApp = GetObject("Outlook.Application")
                        On Error GoTo 0
                        If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
                        Do: Loop Until Not OutApp Is Nothing
                    Set OutMail = OutApp.CreateItem(0)
                    Set bng = wsEmail.Cells(RowNo, "A")
                    FPath = Application.ActiveWorkbook.Path
                    FName = bng.Hyperlinks(1).Address
                    Ease = FPath & "\" & FName
                    With OutMail
                        email = wsEmail.Cells(RowNo, "F")
                        DocT = wsEmail.Cells(RowNo, "D")
                        SubJ = "Automated E-mail - Document Due " & wsEmail.Cells(RowNo, "I")
                        Msg = ""
                        
                        Msg = "Good Day" & "," & vbCrLf & vbCrLf _
                            & "This is an automated e-mail to let you know that document" & vbCrLf _
                            & wsEmail.Cells(RowNo, "C") & " - " & DocT & vbCrLf _
                            & "That was issued for " & wsEmail.Cells(RowNo, "G") & " is due on " & wsEmail.Cells(RowNo, "I") & "." & vbCrLf & vbCrLf _
                            & "Many Thanks, " & vbCrLf & vbCrLf & "AutoMech"
                            
                        .To = email
                        .CC = ""
                        .SentOnBehalfOfName = "PPU Document Control"
                        .Subject = SubJ
                        .ReadReceiptRequested = False
                        .Body = Msg
                        .Attachments.Add (Ease)
                        .Display
    
                    End With
                Set OutApp = Nothing
                Set OutMail = Nothing
                Set bng = Nothing
                .Cells(RowNo, "L") = "RS"
            End If
         Next
        End With
    End Sub

  21. #21
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    This error occurs if there is no matching value.

    Will this happen ?

  22. #22
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    I'm so confused by this all. I can't see any little mistakes which is causing this error. It obviously works for the first loop because it picks up the first e-mail address and stores the second as a(x) but that's when the error occurs

  23. #23
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    Just make sure that all the names and the corresponding email id's are there in the contacts sheet.

  24. #24
    Forum Contributor
    Join Date
    01-21-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    258

    Re: Split contents of cell into single names then search for names on different sheet.

    :/ got it, after hours

    it was in this line
     a = Split(wsEmail.Cells(RowNo, "F"), ";")
    all I needed to do was add in a space
     a = Split(wsEmail.Cells(RowNo, "F"), "; ")

  25. #25
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Split contents of cell into single names then search for names on different sheet.

    Great, you got this thing to work.

    So your delimiter is a ; and a space.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 11
    Last Post: 10-16-2013, 10:21 PM
  2. [SOLVED] Search a list of names and automatically return any names not already included in table
    By bishbash89 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-21-2013, 09:06 AM
  3. [SOLVED] Match names on one spreadsheet to the names on another then copy contents of another cell
    By TYOsborn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2013, 05:06 PM
  4. [SOLVED] How do you split last names and two-part first names from one cell?
    By expectedlyunexpected in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-06-2012, 05:02 AM
  5. [SOLVED] Trim cell contents-split the names
    By Kim C via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-12-2005, 06:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1