compare first 2 letters of cell and clear if not there

bmwbuyer2007

Board Regular
Joined
Jul 19, 2007
Messages
82
Hello All,

Here's one for you!!!

I have information in rows b2:b3567

and i have information in rows d2:d375

I would like to compare the first 3 letters of each line of data in d2:d375 against the first 3 letters in b2:b3567 and clear the contents of any within b2:b3567 if the first 3 letters do not match the first 3 letters in d2:d375.

if that makes sense !?!?

please help!!!

Cord.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Do you mean to check the first 3 letters of each cell in B against every cell in D and clear it if there is no match at all?
 
Upvote 0
Lewiy!!!

How are you?

yes you're right compare every cell but only clear the data in cells b2:b3567 if there is no match within the first 3 letters against d2:d375
 
Upvote 0
Ok, try this:
Code:
Sub MyMacro()
Application.ScreenUpdating = False
Dim b As Long
Dim d As Long
Dim flag
For b = 2 To 3567
    flag = False
    For d = 2 To 375
        If Left(Cells(b, 2), 3) = Left(Cells(d, 4), 3) Then
            flag = True
        End If
    Next d
    If flag = True Then
        Cells(b, 2).ClearContents
    End If
Next b
Application.ScreenUpdating = True
End Sub
 
Upvote 0
that worked to remove the ones which did match, so i changed your flag = true statement to flag = false and hey presto !!!

thanks again lewiy, you trully are a credit to this forum!!!
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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