If with hyphen

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi everyone

I need to add a text to the column C if the text in column F like P-D, or P-E so on. I have done the code but nothing has occurred and I think it may be because of the hyphen. I want to make the criteria either P-E or P-K or P-H then shows as 'No', however I am unsure should I use OR or AND in such case. Please could anyone advise? Many thanks.

Code:
Sheets("Data").Select
Dim i As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To lastrow
If Cells(i, 6).Value Like "P-D" Then
    Cells(i, 3).Value = "Yes"
ElseIf Cells(i, 6).Value Like "P-E" And Cells(i, 6).Value Like "P-K" And Cells(i, 6).Value Like "P-H" Then
    Cells(i, 3).Value = "No"

ElseIf Cells(i, 6).Value = "P-S" And Cells(i, 6).Value Like "P-T" And Cells(i, 6).Value Like "P-M" Then
    Cells(i, 3).Value = "Done"

Else: Cells(i, 3).Value = "Others"

End If
Next I
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I have changed them to 'Or' instead of 'And', however nothing happened. I wonder is it something to do with the hyphen "P-E" etc.?
 
Upvote 0
Add an * before & after each value like "*P-D*"
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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