VBA Code to Copy Row based on multiple conditions

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Hello and thanks in advance. My objective is to copy a row from one sheet to the next based on if two of the cells meet the following conditions.

If column A equals a value say "Home" and column M does not equal "Red", "Green", or "Yellow".

I have the code for everything else except on writing the conditions. I've tried the following:

If (Cells(i, 1) = "Home") And (Cells(i, 13) <> "Red" or Cells(i, 13) <> "Green" Or Cells(i, 13) <> "Yellow")

I've also tried combinations of this statement where I make multiple loops, but anything I've tried gets the incorrect result.

Any assistance will be much appreciated.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
The comparisons are case sensitive and the logic is not correct

Maybe something like this

Code:
If UCase(Cells(i, 1)) = "HOME" And UCase(Cells(i, 13)) <> "RED" _
    And UCase(Cells(i, 13)) <> "GREEN" And UCase(Cells(i, 13)) <> "YELLOW" Then
    'your code here
End If

Hope this helps

M.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,416
Messages
6,124,772
Members
449,187
Latest member
hermansoa

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