Modify a cell value if two other cells contain certain value

zack8576

Active Member
Joined
Dec 27, 2021
Messages
271
Office Version
  1. 365
Platform
  1. Windows
I need to modify some excel files, if column K contains "AO", "COVER", and column N contains "Tampa"
then any "Riser", "Cone", 'Top slab" (column K) with the same item label (column B) gets the letter J at the end of the value in column D
so in the screenshot below, rows 2 and 3 will be: F14632J and F14824J

I have a partially working code that does exactly this if N contains Tampa, how do I modify my code to have it look for AO COVER in column K ?


1672955363151.png


VBA Code:
Sub CityOfTampa()
    Dim c As Variant
    For Each c In Range("N2:N" & Cells(Rows.Count, 1).End(3).Row)
        If c Like "*Tampa*" Or _
           c Like "*Tampa*" Then Tampa = c.Offset(, -9)
        For Each d In Range("K2:K" & Cells(Rows.Count, 1).End(3).Row)
            If d Like "*4'*" And d Like "*Riser*" Or _
               d Like "*4'*" And d Like "*Top Slab*" Or _
               d Like "*4'*" And d Like "*Cone*" Or _
               d Like "*5'*" And d Like "*Cone*" Then
                If d.Offset(, 3) Like "*Tampa*" Then
                    If Right(d.Offset(, -7), 1) <> "J" Then
                        d.Offset(, -7) = d.Offset(, -7) & "J"
                    End If
                End If
            End If
        Next d
    Next c
End Sub
 

Attachments

  • 1672954906257.png
    1672954906257.png
    197.5 KB · Views: 15
No.
Dictionary's only add value if there is an exact match and your example is all based on if statements using partial matches (wildcards).
In the original problem we were finding a description with AO COVER. The dictionary did not help with finding AO COVER.
What it helped with was the next stage. The row with AO COVER had a Type in Column B. We wanted to capture that type in the dictionary so that we could then loop through the rows a second time and further process any row that had that same type by checking the type for each row to see if we held it in the dictionary.
Okay, thank you. The long block of code is working just fine right. I just wanted to see if there is a way to code it shorter. I will leave it the way it is for now . :)
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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