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:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
14,778
Office Version
  1. 2010
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
14,778
Office Version
  1. 2010
Platform
  1. Windows
can you put your complete code and also if you have other macros?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,713
Messages
5,833,269
Members
430,200
Latest member
ADLHMA2022

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
Top