Combining Fors and Ifs

S

Sandy

Is it possible to combine the following :-

For Each MyCell In Sheets("Current Round Detailed").Range("C10:K10")
If (MyCell.Value > 0 And MyCell.Offset(12).Value = vbNullString) Or
_
(MyCell.Value > 1 And MyCell.Offset(14).Value = vbNullString)
Then

MsgBox "xxxxxxxxx"

Exit Sub
End If
Next MyCell

For Each MyCell In Sheets("Current Round Detailed").Range("C16:K16")
If (MyCell.Value > 0 And MyCell.Offset(17).Value = vbNullString) Or
_
(MyCell.Value > 1 And MyCell.Offset(19).Value = vbNullString)
Then

MsgBox "yyyyyyyyyyy"

Exit Sub
End If
Next MyCell

into something along the lines of :-

If
For Each MyCell In Sheets("Current Round Detailed").Range("C10:K10")
If (MyCell.Value > 0 And MyCell.Offset(12).Value = vbNullString) Or
_
(MyCell.Value > 1 And MyCell.Offset(14).Value = vbNullString)
End If
Next MyCell

Or

For Each MyCell In Sheets("Current Round Detailed").Range("C16:K16")
If (MyCell.Value > 0 And MyCell.Offset(17).Value = vbNullString) Or
_
(MyCell.Value > 1 And MyCell.Offset(19).Value = vbNullString)
End If
Next MyCell
Then "zzzzzzzzzzzzzzzz"

Thanks in advance
Sandy
 
M

Mark Ivey

See if something like this will work out...

Mark

'**************************************************************
Dim row As Long
Dim col As Long

For row = 16 To 20 ' rows 16 to 20
For col = 3 To 11 ' columns C to K
If Cells(row, col).Value > 0 And _
Cells(row, col).Offset(17).Value = vbNullString Then
' Do something here
End If
Next
Next

' Take out the for loop involving the row if you do not need it
' and define "row" to equal whatever you need like this:
' row = 10
' before the for loop
 
S

Sandy

Mark
Sorry for delay in responding but I was away for a bit but thank you I
managed with your guidance.
Sandy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top