PC Review


Reply
Thread Tools Rate Thread

Combining Fors and Ifs

 
 
Sandy
Guest
Posts: n/a
 
      15th Mar 2008
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

 
Reply With Quote
 
 
 
 
Mark Ivey
Guest
Posts: n/a
 
      15th Mar 2008
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





"Sandy" <(E-Mail Removed)> wrote in message
news:CBF01954-F28B-4E29-8F2E-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Sandy
Guest
Posts: n/a
 
      20th Mar 2008
Mark
Sorry for delay in responding but I was away for a bit but thank you I
managed with your guidance.
Sandy

"Mark Ivey" <(E-Mail Removed)> wrote in message
news:B78F4D6E-166B-4912-A127-(E-Mail Removed)...
> 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
>
>
>
>
>
> "Sandy" <(E-Mail Removed)> wrote in message
> news:CBF01954-F28B-4E29-8F2E-(E-Mail Removed)...
>> 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

>

 
Reply With Quote
 
Mark Ivey
Guest
Posts: n/a
 
      21st Mar 2008
Glad to help...

Mark

"Sandy" <(E-Mail Removed)> wrote in message
news:6A6DED19-D841-48DC-B74F-(E-Mail Removed)...
> Mark
> Sorry for delay in responding but I was away for a bit but thank you I
> managed with your guidance.
> Sandy
>
> "Mark Ivey" <(E-Mail Removed)> wrote in message
> news:B78F4D6E-166B-4912-A127-(E-Mail Removed)...
>> 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
>>
>>
>>
>>
>>
>> "Sandy" <(E-Mail Removed)> wrote in message
>> news:CBF01954-F28B-4E29-8F2E-(E-Mail Removed)...
>>> 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

>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining the best of RA and RD =?Utf-8?B?SmFzb25M?= Windows XP Work Remotely 3 6th Jul 2007 11:15 AM
Combining VBA and SQL =?Utf-8?B?RWxsZW5N?= Microsoft Access VBA Modules 2 28th Jun 2007 07:45 PM
Combining =?Utf-8?B?VGFtc2lu?= Microsoft Excel Charting 0 5th Mar 2007 03:14 PM
Combining 4:3 and 16:9 =?Utf-8?B?ZWZyb3N0?= Windows XP MovieMaker 2 28th Nov 2006 04:53 AM
Combining IF's =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 1 27th Nov 2006 05:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:36 PM.