So, something like:
Public Sub CheckDatabase()
Dim rngColumnStart As Excel.Range
Dim arrValues As Variant
Dim intCol As Integer
Dim lngLastRow As Long
Dim lngCurrRow As Long
Set rngColumnStart = Worksheets("Database").Range("S3")
intCol = rngColumnStart.Column
On Error Resume Next
lngLastRow = rngColumnStart.Parent.Columns(intCol).Find(What:="*", _
After:=Worksheets("Database").Cells(1, intCol), _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
LookAt:=xlPart, LookIn:=xlValues).Row
If Err > 0 Then
lngLastRow = 0
End If
On Error GoTo 0
If lngLastRow > 0 Then
arrValues = rngColumnStart.Resize(lngLastRow - rngColumnStart.Row + 1, 1).Value
For lngCurrRow = LBound(arrValues) To UBound(arrValues)
If arrValues(lngCurrRow, 1) = 1 Then
Call SendEMail(rngColumnStart.Offset(lngCurrRow - 1, 1 - rngColumnStart.Column))
End If
Next lngCurrRow
End If
End Sub
Change the Range to match the starting cell of your column, I guessed it was Database!S3. This will read the entire column into an array, then loop through the array looking for 1's. When it finds one, it will call the SendEMail procedure, passing it a range of column A in the selected row. SendEMail could start like this:
Public Sub SendEMail(ByVal rngStart As Excel.Range)
Dim arrComplaint As Variant
arrComplaint = rngStart.Resize(1, 20).Value
End Sub
Bookmarks