vba help - Keep partial find while saving workbook

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want to find exact match while Running Macro, and while saving ACTIVE workbook I want find function back to Partial Match.

what is the correct way to do that.

VBA Code:
Sub test()
Dim FoundItem As Range
On Error Resume Next
    Set FoundItem = Range("A2:a5").Find("Chicago", LookIn:=xlValues, LookAt:=xlWhole)
    Set FoundItem = Range("A2:a5").Find("xyz", LookIn:=xlValues, LookAt:=xlPart)
On Error GoTo 0
Activeworkbook.saveas thisworkbook.path & "\" & "xyz.xlsx"
end sub

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Maybe create a separate variable for each and only do the save if the second variable has found something i.e.

VBA Code:
Option Explicit
Sub test()
    Dim FoundItemWhole As Range, FoundItemPart As Range
    On Error Resume Next
        Set FoundItemWhole = Range("A2:A5").Find("Chicago", LookIn:=xlValues, LookAt:=xlWhole)
        Set FoundItemPart = Range("A2:A5").Find("xyz", LookIn:=xlValues, LookAt:=xlPart)
    On Error GoTo 0
    If Not FoundItemPart Is Nothing Then
        ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & FoundItemPart.Value & ".xlsx"
    Else
        MsgBox "There was no partial match found to name the workbook.", vbExclamation
    End If
End Sub

Hope that helps.

Robert
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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