Changing a column in Excel from "9" to "X" when another column in Equal "DIFFS"


What would the code be to change a value in Column "I" that is equal to "9"  to "X" when Column "B" on the same row is equal to "DIFFS"?
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this.
Public Sub ChngDiffs()
Dim intRows As Integer
Dim i As Integer
Dim rng As Range

Set rng = ActiveSheet.UsedRange
intRows = rng.Rows.Count

i = 1
Do While i <= intRows
    If Cells(i, 9) = 9 And Cells(i, 2) = "DIFFS" Then Cells(i, 9) = "X"
i = i + 1
Set rng = Nothing
End Sub

Open in new window

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this which doesn't loop through cells....
Sub Change9ToX()
Dim lr As Long
Dim found As Boolean
Application.ScreenUpdating = False
lr = Cells(Rows.Count, "I").End(xlUp).Row
With Rows(1)   'Assuming the header row is row1
   .AutoFilter field:=2, Criteria1:="DIFFS"
   .AutoFilter field:=9, Criteria1:=9
   If Range("I1:I" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
      found = True
      Range("I2:I" & lr).SpecialCells(xlCellTypeVisible).Value = "X"
   End If
End With
If found Then
   MsgBox "All the 9's have been changed to ""X"" where column B had ""DIFFS"".", vbInformation, "Done"
   MsgBox "No such cells were found in column I.", vbExclamation, "No Cells Found!"
End If
Application.ScreenUpdating = True
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.