Access VBA | How to replace parts of a string with another string

calendar_today Asked Dec 18, 2011
thumb_up 44 upvotes
history Updated April 14, 2026

Direct Answer

Use Access's VBA function Replace(text, find, replacement): Dim result As String result = Replace("Some sentence containing Avenue in it.", "Avenue", "Ave"). This is a 4-line VBA Core snippet, ranked #6th of 95 by community upvote score, from 2011.


The Problem (Q-score 25, ranked #6th of 95 in the VBA Core archive)

The scenario as originally posted in 2011

I am trying to create a piece of code that replaces one word with another.
Example: Replace Avenue with Ave and North with N.
I am using MS Access, I could use SQL REPLACE Function but I want to do this in VBA using Access module so that I can attached the function to other column.

I am not sure where to start with this, so any input will be greatly appreciated.

Guy

Why community consensus is tight on this one

Across 95 VBA Core entries in the archive, the accepted answer here holds elite answer (top 10 %%) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — elite answer (top 10 %%) (+44)

4-line VBA Core pattern (copy-ready)

Use Access’s VBA function Replace(text, find, replacement):

Dim result As String

result = Replace("Some sentence containing Avenue in it.", "Avenue", "Ave")


When to Use It — vintage (14+ years old, pre-2013)

A top-10 VBA Core pattern — why it still holds up

Ranks #6th of 95 in the VBA Core archive. The only pattern ranked immediately above it is “html parsing of cricinfo scorecards” — compare both if you’re choosing between approaches.

What changed between 2011 and 2026

The answer is 15 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Why is this answer the top decile of VBA Core Q&A?
expand_more

Answer score +44 vs the VBA Core archive median ~14; this entry is elite. The score plus 25 supporting upvotes on the question itself (+25) means the asker and 43 subsequent voters all validated the approach.

Does the 4-line snippet run as-is in Office 2026?
expand_more

Yes. The 4-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

This answer is 15 years old. Is it still relevant in 2026?
expand_more

Published 2011, which is 15 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #5?
expand_more

The pattern one rank above is “html parsing of cricinfo scorecards”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 25, Answer-score 44, original post 2011, ranked #6th of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba