ISSUE WITH LIKE FUNCTION AND STRING

MadMatLePsyke

New Member
Joined
Jan 3, 2023
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Below my code
IOI ="xxx yyy zzz "
My issue with my IOI string is an email adress, I have one email on my Rng1 but Vba not going to Else

Could you please help me ?

VBA Code:
Sub PMBLOCK()

Set Wb = ThisWorkbook
Set WsB = Sheets("BOARD")
Set WsDL = Sheets("DL")

Dim LeMail As Variant
Dim Side As String
Dim Qty As String
Dim Stock As String
Dim Name As String
Dim IOI As String
Dim Pays As String
Dim R As Integer
Dim Rng1 As Range
Dim Ad As String

WsB.Select

Qty = WsB.Range("G27")
Stock = WsB.Range("C24")
Name = WsB.Range("E24")
IOI = WsB.Range("E30").Value


    If WsB.Range("V30").Value = "B" Then
            Side = "Block Buyer"
            Else: Side = "Block Seller"
    End If

  
WsDL.Select
Pays = Cells(1, 2).Value

    If Pays = "FRANCE" Then
        R = Application.WorksheetFunction.CountA(Range("A:A"))
        Set Rng1 = Range(Cells(3, 1), Cells(R, 1))
            For Each cel In Rng1
                If Not cel.Value Like IOI And cel.Value <> "" Then
                    Ad = Ad & ";" & cel.Value
                Else: Ad = Ad
                End If
            Next
        Else: R = Application.WorksheetFunction.CountA(Range("C:C"))
        Set Rng1 = Range(Cells(3, 3), Cells(R, 3))
            For Each cel In Rng1
                If Not cel.Value Like IOI And cel.Value <> "" Then
                    Ad = Ad & ";" & cel.Value
                Else: Ad = Ad
                End If
            Next
    End If
 
Set Wb = ThisWorkbook
Set WsB = Sheets("BOARD")
Set WsDL = Sheets("DL")
On the code so :
The name of WsB is BOARD
The name of WsDL is DL
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Why would it go to the Else part? If the cell value is not like IOI (and it isn't in your example) then the first part of the If clause is true. The cell value is also not "", so that part is true too, and the whole If condition is true.
 
Upvote 0
Why would it go to the Else part? If the cell value is not like IOI (and it isn't in your example) then the first part of the If clause is true. The cell value is also not "", so that part is true too, and the whole If condition is true.

My issue is when IOI is ie MAMAN TRADING and in Rng1 I have an email adress ie test@maman.com it is not going to the Else part, but adding this email adress to my Ad string
Don't understant why
 
Upvote 0
Because those two value are not the same. Therefore cell.value Like IOI is False. Not False =True, so both parts of the If clause are true.
 
Upvote 0
Because those two value are not the same. Therefore cell.value Like IOI is False. Not False =True, so both parts of the If clause are true.

Agreed
But if I'm doing

VBA Code:
If cel.value like IOI and cel.value <>""
I don't have any email adress in BCC / ad string value is ""
 
Upvote 0
My issue is when IOI is ie MAMAN TRADING and in Rng1 I have an email adress ie test@maman.com it is not going to the Else part, but adding this email adress to my Ad string
Don't understant why
1) the like statement is case sensitive
2) What is on the right has to "part" of what is on the left
3) You need wildcards "*"

Something like this would work.
VBA Code:
ucase("test@maman.com") like "*MAMAN*"
 
Upvote 0
I have logged off for the night but I don't believe your code is showing us where you are assigning something to "to or cc or bc" and both your If and else parts are using the variable Ad, so we really can't understand how you expect to give a different value to bc.
 
Upvote 0
I have logged off for the night but I don't believe your code is showing us where you are assigning something to "to or cc or bc" and both your If and else parts are using the variable Ad, so we really can't understand how you expect to give a different value to bc.
my code is :

Sub PMBLOCK()

Set Wb = ThisWorkbook
Set WsB = Sheets("BOARD")
Set WsDL = Sheets("DL")

Dim LeMail As Variant
Dim Side As String
Dim Qty As String
Dim Stock As String
Dim Name As String
Dim IOI As Variant
Dim Pays As String
Dim R As Integer
Dim Rng1 As Range
Dim Ad As String

WsB.Select

Qty = WsB.Range("G27")
Stock = WsB.Range("C24")
Name = WsB.Range("E24")
Range("E30").Copy

If WsB.Range("V30").Value = "B" Then
Side = "Block Buyer"
Else: Side = "Block Seller"
End If

IOI = Range("E30").Value


WsDL.Select
Cells(2, 2).PasteSpecial Paste:=xlValues



Pays = Cells(1, 2).Value

If Pays = "FRANCE" Then
R = Application.WorksheetFunction.CountA(Range("A:A"))
Set Rng1 = Range(Cells(3, 1), Cells(R, 1))
For Each cel In Rng1
If cel.Value Like IOI Then
Ad = Ad & ";" & cel.Value
Else: Ad = Ad
End If
Next
Else: R = Application.WorksheetFunction.CountA(Range("C:C"))
Set Rng1 = Range(Cells(3, 3), Cells(R, 3))
For Each cel In Rng1
If cel.Value Like IOI Then
Ad = Ad & ";" & cel.Value
Else: Ad = Ad
End If
Next
End If

Set LeMail = CreateObject("Outlook.Application")

With LeMail.CreateItem(olMailItem)
.Subject = "*** XXXXX : " & Side & " " & Qty & " " & Stock & " ( " & Name & " ) ***"
.BCC = Ad
.HTMLBody = "XXXX ""
.Display
End With

WsB.Select
Cells(1, 1).Select
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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