Solved

I want to replace all Excel cell content in a range except for cells begining with specfic text

Posted on 2014-09-10
2
201 Views
Last Modified: 2014-09-10
I want to use a VBA module to replace all Excel cell content in a range except for cells begining with specfic text.
0
Comment
Question by:AMixMaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 500 total points
ID: 40315597
the following code will do what you want.

How to set up and run:

(1) startingStringValue needs to hold the string that you want to search for that you DO NOT want to change in the cell.
(2) newCellValue needs to hold the NEW value that you want the cells changed to.
(3) select/highlight the range you want the vba code to consider... then run the macro.

 

Sub test()
    Dim StartStringValue As String
    Dim newCellValue As String
    
    StartStringValue = "t"
    newCellValue = "NewValue"
    
    Dim aCell As Range

    For Each aCell In Selection
        If Left(aCell.Value, Len(StartStringValue)) <> StartStringValue Then
            aCell = newCellValue
        End If
    Next
End Sub

Open in new window

0
 

Author Closing Comment

by:AMixMaster
ID: 40315630
This elusive bit of code worked absolutely perfect!
Thanks Ken!
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Viewers will learn various types of data validation for different data types in Excel 2013.
Video by: Zack
Viewers will learn about using Excel in a browser with Excel Online.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question