VBA - find (with wildcard) and replace

energy_excel

New Member
Joined
Mar 6, 2023
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm got a column with 3k rows of data. Data in each cell is a string and in the following format:

name[40%], name2[20%], name3[5%], name4[60%]

but at times, those inputting the information forget to put a comma between names, so I get something like this:

name[40%], name2[20%]name3[5%], name4[60%]

I've gotten this far in my macro but can't figure out how to replace.....

If Range(a1).Value Like "*%][A-Z]*" Then ?????

how do i place the comma in between the closing bracket and the wildcard letter??

Thank you in advance!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Interesting to me that your expression does not find that the string with missing comma in A4 is found. The code skips over my msgbox test:
VBA Code:
If Range("A4") Like "*%][A-Z]*" Then
   MsgBox Range("A4")
End If
I did come up with a longer solution by splitting the delimited (,) portions into an array but it's kind of convoluted. If you don't get a RegEx solution I can work on it a bit to make it more decipherable.
From this
name[40%], name2[20%]name3[5%], name4[60%]

I got this
name[40%], name2[20%], name3[5%], name4[60%]
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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