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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
 
Upvote 0
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.
 
Upvote 0
can you put your complete code and also if you have other macros?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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