Adding Additional Criteria

loss1003

Board Regular
Joined
Jul 2, 2008
Messages
100
Code:
Sub SwapperTEST()
    ActiveWorkbook.Sheets(1).Activate
    Dim cell As Range
    Dim v1 As String, v2 As String, id1 As String, id2 As String
     
    For Each cell In Range("F:F")
         
        If cell.Value = "Vendor A" And cell.Offset(0, -1) > 1 Then
            v1 = cell.Offset(0, -2).Value
            v2 = cell.Offset(1, -2).Value
             
            cell.Offset(0, -2).Value = v2
            cell.Offset(1, -2).Value = v1
             
            id1 = cell.Offset(0, -1).Value
            id2 = cell.Offset(1, -1).Value
             
            cell.Offset(0, -1).Value = id2
            cell.Offset(1, -1).Value = id1
            
         
         End If
         
    Next cell
     
End Sub

How can I add the following additional criteria to the above code.

If cell.Value = "Vendor A" And cell.Offset(0, -1) > 1 Then
If cell.Value = "Vendor B" And cell.Offset(0, -1) > 1 Then
If cell.Value = "Vendor C" And cell.Offset(0, -1) > 1 Then
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi loss1003,

Try just in the way as you already have:
Code:
Sub SwapperTEST()
    ActiveWorkbook.Sheets(1).Activate
    Dim cell As Range
    Dim v1 As String, v2 As String, id1 As String, id2 As String
     
    For Each cell In Range("F:F")
         
        If cell.Value = "Vendor A" And cell.Offset(0, -1) > 1 Then
            v1 = cell.Offset(0, -2).Value
            v2 = cell.Offset(1, -2).Value
             
            cell.Offset(0, -2).Value = v2
            cell.Offset(1, -2).Value = v1
             
            id1 = cell.Offset(0, -1).Value
            id2 = cell.Offset(1, -1).Value
             
            cell.Offset(0, -1).Value = id2
            cell.Offset(1, -1).Value = id1   
         End If

       If cell.Value = "Vendor B" And cell.Offset(0, -1) > 1 Then
[COLOR=Navy]             [COLOR=Green] 'Do something[/COLOR][/COLOR]
       End If
        If cell.Value = "Vendor C" And cell.Offset(0, -1) > 1 Then
[COLOR=Navy]             [COLOR=Green] 'Do something[/COLOR][/COLOR]
        End If         
    Next cell
     
End Sub
Or depending how your code it works could be use it the following:
Code:
If (cell.Value = "Vendor A" Or cell.Value = "Vendor B" Or cell.Value = "Vendor C" ) And cell.Offset(0, -1) > 1 Then
 [COLOR=Green]   'your code[/COLOR]
End If
Hope this helps.

Regards
 
Upvote 0
That helped. But, now I need to change the criteria for Vendor B <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
If cell.Value = "Vendor B" And cell.Offset(0, -1) > 3 Then<o:p></o:p>
<o:p> </o:p>
However, I need that code to run exact time the codes for vendor A and C run.
 
Upvote 0
However, I need that code to run exact time the codes for vendor A and C run.
Try with:
Code:
    If cell.Value = "Vendor A" And cell.Offset(0, -1) > 1 Or _
    cell.Value = "Vendor B" And cell.Offset(0, -1) > 3 Or _
    cell.Value = "Vendor C" And cell.Offset(0, -1) > 1 Then
       [COLOR=Green] 'your code[/COLOR]
    End If
Or
Code:
[COLOR=Navy]
[/COLOR][COLOR=Navy][COLOR=Black]If (cell.Value = "Vendor A" Or cell.Value = "Vendor C") And cell.Offset(0, -1) > 1 Or _
    cell.Value = "Vendor B" And cell.Offset(0, -1) > 3 Then[/COLOR]
   [COLOR=Green]     'your code[/COLOR]
    [COLOR=Black]End If[/COLOR][/COLOR]

Regards.
 
Last edited:
Upvote 0
Thanks..now i'm having difficulties with the code it will not repeadely loop through the Range until it meets the conditions/criteria.

It merelys pushes the cells down one row and replaces them with the cells from the row below, one time through the range. I need the process to repeat until all the rows meet the conditions.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top