Evaluate IF(AND is erasing all values

johnnyL

Well-known Member
Joined
Nov 7, 2011
Messages
4,546
Office Version
  1. 2007
Platform
  1. Windows
Trying to get Evaluate(IF(AND to work.

Code that works:
VBA Code:
Sub TestEvaluateIF()
'
' Check values in A1:A10
'
    With Range(Cells(1, 1), Cells(10, 1))
        .Value = Evaluate("IF(" & .Address & "= ""Good"", ""OK""," & .Address & ")")        '   If cell in Column A range = 'Good' then change Column A
'                                                                                           '           cell to 'OK' Else leave the value as is
    End With
End Sub


Code that erases all values from Column A:
VBA Code:
Sub TestEvaluateIF_And()
'
' Check values in A1:B10 via offset ... This erases all values from Column A for some reason?
'
    With Range(Cells(1, 1), Cells(10, 1))
        .Value = Evaluate("IF(AND(" & .Address & "= ""Definitely"", " & _
                .Offset(, 1).Address & "= ""Good""), ""OK""," & .Address & ")")             '   If cell in Column A range = 'Definitely' & cell
'                                                                                           '           in Column B range = 'Good' then change
'                                                                                           '           Column A cell to 'OK' Else leave the value as is
    End With
End Sub


Book1
ABC
1DefinitelyGood
2DefinitelyGood
3MaybeBad
4MaybeGood
5MaybeBad
6DefinitelyGood
7DefinitelyBAD
8MaybeBAD
9DefinitelyGood
10DefinitelyGood
11
Sheet1


Before I smash this computer, Please let me know what I am messing up.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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