+ Reply to Thread
Results 1 to 5 of 5

Code For Whole Column Instead of One Cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2008
    Location
    New Jersey
    Posts
    52

    Code For Whole Column Instead of One Cell

    Hey guys,

    How would I edit this line to send an email to each of the email addresses in column "BF instead of just one?"

    .To = "[email protected]"
    I'm not sure how to write it but maybe a loop would do this?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Yes a loop could do this.


    Dim x as Integer
    
       For x = 1 To Range("MyEmailList").Rows.Count
          'your code for creating emails
    
           .To = Range("MyEmailList").Cells(x,1)
    
       Next x

  3. #3
    Registered User
    Join Date
    07-08-2008
    Location
    New Jersey
    Posts
    52
    Thank you so much. You have no idea how much this has helped me out heh

    Here is my code if anyone ever has the same situation:

    Sub Email()
        Dim Sendrng As Range
        Dim x As Integer
    
       For x = 1 To Range("MyEmailList").Rows.Count
    
        On Error GoTo StopMacro
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        Set Sendrng = Selection
    
        With Sendrng
    
            ActiveWorkbook.EnvelopeVisible = True
            With .Parent.MailEnvelope
    
                With .Item
                    .To = Range("MyEmailList").Cells(x, 1)
                    .Subject = "Whatever my Boss wanted to put in here..."
                    .Send
                End With
    
            End With
        End With
    
    Next x
    
    StopMacro:
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
        ActiveWorkbook.EnvelopeVisible = False
    
    End Sub
    Richard, Thanks again

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Glad to help, and thanks for the feedback and sharing the code with others.

    Just one other observation you might find useful. When I had something similar in my previous working life, I used to use a few cells on the spreadsheet to hold various messages, naming them Message1, Message2 etc. Then in the VBA code I used

    .Subject = Range("Message1") & " " & Range("Message2") '....etc

    or even use IF..Then structures with .Subject message ranges depending on the results of such tests.

    Doing it this way means standard messages can be edited by a non VBA user just by changing the sheet. If the message cells are empty then they are not printed.

    HTH

  5. #5
    Registered User
    Join Date
    07-08-2008
    Location
    New Jersey
    Posts
    52
    Thats a great idea, thanks for the suggestions. It would make things a lot easier to code that way.

    Anything to help simplify and understand this better is a great help.

    Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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