Searching for text string using If function.

LauraEFord

New Member
Joined
May 13, 2014
Messages
5
I have macro in VBA that uses a data set in excel. Then it filters all but one specific vendor. Everyone else is removed from that data set. Unfilter. Then I'm left with headers only and no data lines (line 2 and below) or I'm left with header data and data in lines 2 and usually more.

Then I have the following.
Dim MyRange as range
Dim FindThis as String
FindThis = "VENDOR's NAME"
Set MyRange = Range ("B2:B65536").Find(What:=FindThis)
If MyRange is Nothing Then
Else

Save the file as Vender.xlsx
Attaches to email etc

End if

If it comes to one of the vendors that is not in the data set, then it just spins and does nothing. So yesterday, i got 6 files and emails and then it stops.
 
Last edited:

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. Windows
I do not understand what the problem is.
You can put your complete code.
What to do if it exists?
What to do if it does not exist?
I tried the following and it works

Code:
    Dim MyRange As Range
    Dim FindThis As String
    
    FindThis = "VENDOR's NAME"
    If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
    
    Set MyRange = Range("B2", Range("B" & Rows.Count).End(xlUp)).Find(What:=FindThis, LookIn:=xlValues, lookat:=xlWhole)
    If MyRange Is Nothing Then
        MsgBox "The vendor does not exist"
    Else
        MsgBox "Start"
        'Save the file as Vender.xlsx
        'Attaches to email etc
        
    End If
 

LauraEFord

New Member
Joined
May 13, 2014
Messages
5
This worked! thank you.

Any suggestions on this.

Is there anyway not to save the file in VFB? I make some changes and when it does "nothing" I get a popup box with an error.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. Windows
can you put your complete code and also if you have other macros?
 

Watch MrExcel Video

Forum statistics

Threads
1,109,032
Messages
5,526,355
Members
409,697
Latest member
christopherlewis1620

This Week's Hot Topics

Top