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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,216,057
Messages
6,128,520
Members
449,456
Latest member
SammMcCandless

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