If Else Vlookup Using vba

Status
Not open for further replies.

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
a good afternoon

I tried to make autoreplay with vlookup and it worked perfectly
but I want if the message is not found in the data base ,, it sends a certain message, namely "Sorry, Message not found"

The problem is in the message not found, can't work

this is my code
VBA Code:
Public Sub Read()
    On Error Resume Next
    
    Dim strMessage As String
    Dim strSplit As Variant
    Dim strLookup As String
    Dim strReply As String
    Dim strNewLine As Variant
    Dim rw As Long
    Dim iRow As Long
    Set ch = New Selenium.ChromeDriver
    Set by = New Selenium.by
    
    ch.AddArgument ("user-data-dir-" & strlocal)
    ch.Start
    ch.Get "https://www.example.com"
    
    
       iRow = Sheets("ChatLog").UsedRange.Rows.Count
       ch.FindElementByClass(NewMessage).Click
      
      
      
      strMessage = ch.FindElementsByClass(MessageList).Text
      
      
      
            strSplit = Split(strMessage, "#")
            strLookup = Application.WorksheetFunction.VLookup(strSplit(0), Sheets("AutoReply").Range("A:C"), 2, 0)
            
            
            
            If strLookup = True Then
            strReply = Application.WorksheetFunction.VLookup(strSplit(0), Sheets("AutoReply").Range("A:C"), 2, 0)
            strNewLine = Split(strReply, vbLf)
            For rw = 0 To UBound(strNewLine, 1)
                ch.FindElementByXPath(ChatBox).SendKeys strNewLine(rw) & ch.Keys.Shift & ch.Keys.Enter & ch.Keys.LeftShift
            Next rw
            ch.SendKeys ch.Keys.Enter
            ch.FindElementsByClass(FindChat)(1).Click
            
            Else
            strReply = "Sorry, Message not found"
            strNewLine = Split(strReply, vbLf)
            For rw = 0 To UBound(strNewLine, 1)
                ch.FindElementByXPath(ChatBox).SendKeys strNewLine(rw) & ch.Keys.Shift & ch.Keys.Enter & ch.Keys.LeftShift
            Next rw
            ch.SendKeys ch.Keys.Enter
            ch.FindElementsByClass(FindChat)(1).Click
            End If
        
      
    End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Duplicate how to make auto message reply with vba ?

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

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