Make a copy of your workbook and test this out in it first. Change the names
of the two worksheets in this code to whatever they're really called in the
workbook. To put the code where you can use it, press [Alt]+[F11] to open
the VB editor. Choose Insert >> Module from the VBE menu. Copy and paste
the code below into the module that appears, make the sheet name changes,
close the VB Editor and use it from Tools >> Macro >> Macros.
I assumed you wanted the email addresses to actually be email links, so I've
coded it that way.
Sub MakeEmailList()
Const sourceSheet = "Sheet1" ' change
Const emailListSheet = "Sheet2" ' change
Dim lastSourceRow As Long
Dim sourcePointer As Long
Dim srcRange As Range
Dim emailRange As Range
Dim emailPointer As Long
If Val(Left(Application.Version, 2)) < 12 Then
'in pre-2007 Excel
lastSourceRow = Worksheets(sourceSheet).Range("A" & _
Rows.Count).End(xlUp).Row
emailPointer = Worksheets(emailListSheet).Range("A" & _
Rows.Count).End(xlUp).Row
Else
'in Excel 2007 (or later)
lastSourceRow = Worksheets(sourceSheet).Range("A" & _
Rows.CountLarge).End(xlUp).Row
emailPointer = Worksheets(emailListSheet).Range("A" & _
Rows.CountLarge).End(xlUp).Row
End If
Set srcRange = Worksheets(sourceSheet).Range("A1")
Set emailRange = Worksheets(emailListSheet).Range("A1")
Do While srcRange.Row + sourcePointer <= lastSourceRow
If Not IsEmpty(srcRange.Offset(sourcePointer, 0)) Then
'some entry in column A
'if also an entry in B, assume an email, copy it
If Not IsEmpty(srcRange.Offset(sourcePointer, 1)) Then
emailRange.Offset(emailPointer, 0).Hyperlinks.Add _
Anchor:=emailRange.Offset(emailPointer, 0), _
Address:="mailto:" & srcRange.Offset(sourcePointer, 1).Value, _
TextToDisplay:=srcRange.Offset(sourcePointer, 1).Value
emailPointer = emailPointer + 1
End If
End If
sourcePointer = sourcePointer + 1
Loop
End Sub
Cathy Landry said:
Hello,
Sheet1 Column A will always contain a mm/yy (we use this for our corp card
programs exp date) Column B will always contain employees email add'y. So,
I'd like to create an email list in sheet2 of all email addresses where the
cells in ColA in Sheet1 are not null. Hope that makes sense