Finding "CL" or "CLOSED" in one clumn and changing to 99% in Another

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Code:
For i = 9 To LastRow
If UCase(Cells(i, "F")) <> "CL" Or UCase(Cells(i, "F")) <> "CLOSED" _
And Cells(i, "B").Value = 100 Then
Cells(i, "B").Value = 99 _
And Cells(i, "E").Formula = "=(E-.3)"
End If
Next i

Hello All...
I have a little problem here.
What I'm trying to accomplish, is for the macro to not find either "CL" or "CLOSED" (upper case should not matter) in column "F" and a 100% in column "B", and changing 100% in Column "B" to a 99%, and then subtracting a .3 from the number in Column E...one row at a time.
The loop is working correctly.

Column "B" is formatted previously with:
Code:
With Range("B9:B6000")
        .Formula = "=1-(C9/D9)"
        .NumberFormat = "0%"
End With

What's happening, is every cell in Column "B", as the loop moves row-to-row, changes the number in column "B", regardless if it's 100% to 0%, and Column "E" number is not getting .3 subtracted.

Where am I going wrong this time!
Thanks for the help
excel 2013
 
Last edited:
Yes, I have "On Error Resume Next", at the beginning.
Then remove it. That is about the worst thing you can do.
All it does is mask any errors in the code & can result in the code working incorrectly as it is here.
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I removed on error resume next, and it gives me a Type Mismatch on this line of code, when it hits the first line with #N/A

Code:
   If UCase(Cells(i, "F")) <> "CL" And UCase(Cells(i, "F")) <> "CLOSED" _
      And Cells(i, "B").Value = 1 Then
         Cells(i, "B").Value = 0.99
         Cells(i, "E") = Cells(i, "E") - 0.3
   End If
 
Upvote 0
Code:
   If Not Application.IsError(Cells(i, "F")) Then
   If UCase(Cells(i, "F")) <> "CL" And UCase(Cells(i, "F")) <> "CLOSED" _
      And Cells(i, "B").Value = 1 Then
         Cells(i, "B").Value = 0.99
         Cells(i, "E") = Cells(i, "E") - 0.3
   End If
    End If

I put the IsError in, which solved the any error part, instead of just looking for #N/A. But it's still is giving me a "Type Mismatch" fault on:
Code:
If UCase(Cells(i, "F")) <> "CL" And UCase(Cells(i, "F")) <> "CLOSED" _
      And Cells(i, "B").Value = 1 Then

Thanks for the help
 
Last edited:
Upvote 0
That's because you have an error in col B.
Try
Code:
   If Not IsError(Cells(i, "B").Value) Then
      If UCase(Cells(i, "F")) <> "CL" And UCase(Cells(i, "F")) <> "CLOSED" _
         And Cells(i, "B").Value = 1 Then
            Cells(i, "B").Value = 0.99
            Cells(i, "E") = Cells(i, "E") - 0.3
      End If
   End If
If you also have formulaic errors in col F, you'll need to add that in as well
 
Upvote 0
An error returned by a formula

Code:
     ' Compute V-Lookup for Finding Closed Status *************************
    With Range("F9:F6000")
        Range("F9:F6000") = Application.WorksheetFunction.VLookup(Sheets("Template").Range("G9:G6000"), _
        Sheets("Template").Range("H9:AQ6000"), 6, False)
        .NumberFormat = "0.0"
    End With

I was thinking this is what you mean, because this is text going into column F, so the number format would not matter.



Also, thanks for finding my mistake on the Type Mismatch error for the error in Column B and not Column F.
I changed it to Column B and it works fine.
Code:
If Not IsError(Cells(i, "B").Value) Then
      If UCase(Cells(i, "F")) <> "CL" And UCase(Cells(i, "F")) <> "CLOSED" _
         And Cells(i, "B").Value = 1 Then
            Cells(i, "B").Value = 0.99
            Cells(i, "E") = Cells(i, "E") - 0.3
      End If
End If
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Code:
[TABLE="width: 515"]
<tbody>[TR]
[TD="class: xl506, width: 103, align: center"]100%
[/TD]
[TD="class: xl507, width: 103, align: center"]0.1
[/TD]
[TD="class: xl507, width: 103, align: center"]85.2
[/TD]
[TD="class: xl507, width: 103, align: center"]85.1
[/TD]
[TD="class: xl507, width: 103, align: center"]QA
[/TD]
[/TR]
</tbody>[/TABLE]

Getting back to this. Here's an example of how the code, for some reason, skips over "QA" in Column F.
The 100% in column B should have changed to 99% and 85.1 in Column E should have changed to 84.8. This only happens with "QA" in Column F, everything else works correctly.
What is it with the letters "QA" to cause excel not to run the code?
Thanks for the help
 
Last edited:
Upvote 0
Check the value in col B, it probably isn't 1.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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