Find in VBA

datauser

New Member
Joined
Sep 4, 2024
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello! I am getting an error message when I use this find formula in vba. It highlights the comma in the red.

Range("B5").Formula2 = "=MID(F5,FIND(",",F5) + 1,FIND(" -", F5) - FIND(",",F5) -1)"
Range("B5").AutoFill Range("B5:B" & Range("C" & Rows.Count).End(xlUp).Row)

1730414475221.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try double quotes
Range("B5").Formula2 = "=MID(F5,FIND("","",F5) + 1,FIND("" -"", F5) - FIND("","",F5) -1)"
 
Upvote 0
A couple of comments.
  • Since you have Microsoft 365 you have more functions available to you now so you could consider this simpler formula

    VBA Code:
    Range("B5").Formula2 = "=INDEX(TEXTSPLIT(F5,{"","","" -""}),2)"

  • Whichever formula you use you can enter them all at once rather than entering one and then using AutoFill. For example

    VBA Code:
    Range("B5:B" & Range("C" & Rows.Count).End(xlUp).Row).Formula2 = "=INDEX(TEXTSPLIT(F5,{"","","" -""}),2)"
 
Upvote 0

Forum statistics

Threads
1,223,604
Messages
6,173,319
Members
452,510
Latest member
RCan29

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