View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Horatio J. Bilge, Jr. Horatio J. Bilge, Jr. is offline
external usenet poster
 
Posts: 135
Default code to check condition for each row

I am trying to write a macro that will check the last cell in each row of a
range against a condition. If the condition is met, then the value of the
first cell in the row is added to a string. The string will be used for a
message box.

The range("A3:P42") has names in the first column, data in the middle
columns, and totals in the last column. I'm trying to use a for-next loop,
but I'm stuck on how to refer to the correct cell. This is what I have tried:

Private Sub cmdErrorCheck_Click()
Dim e As String

For Each .Row In Me.Range("A3:P42")
If [the last cell].Value 4 Then
e = e & [the first cell].Value
End If
Next .Row

MsgBox "There is an error on these people: " & e

End Sub