VBA Syntax Error when replacing

loribear180

New Member
Joined
Apr 13, 2021
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

Last year I received help in creating the code attached. My export changed and now I need to update the replace parameters, however, are there limits to what can be replaced? I'm trying to replace an entire paragraph with a simple 'Y' but I keep receiving a 'Syntax Error' when I try to run the code.

My export has 6 different answers that I need to replace with simple Y or N. The specific language I'm struggling with reads:
Veteran. The individual is defined as an individual who has served in (and has been honorably discharged from) the following branches of service: The U.S. Army, Navy, Air Force, Marine Corps, or Coast Guard or the U.S. Public Health; Service under Title 42, United States Code, Section 201; The Texas Military Forces as defined by Texas Government Code, Section 437.001; or an auxiliary service of one of the branches of the U.S. Armed Forces.

1618341398501.png


Am I having this issue because it's too long of an answer and contains parentheses, colons, semi-colons, and every other punctuation mark? This is obviously not my expertise and I can't figure out what's wrong, I tried setting MatchCase to True hoping that would possibly fix it, but nothing. Again, I really appreciate your assistance and patience.?
 
You could shorten the string & use a wildcard like
VBA Code:
Selection.Replace "Veteran. The individual is defined as an individual who has served in (and has been honorably discharged from) the following branches of service: The U.S. Army, Navy, Air Force, Marine Corps, or Coast Guard or the U.S.*", "Y", xlPart, , False, , False, False
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You could shorten the string & use a wildcard like
VBA Code:
Selection.Replace "Veteran. The individual is defined as an individual who has served in (and has been honorably discharged from) the following branches of service: The U.S. Army, Navy, Air Force, Marine Corps, or Coast Guard or the U.S.*", "Y", xlPart, , False, , False, False
Fluff thank you so much, that did it!! I learned what a wildcard can do (y)
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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