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
188 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 the basics of the new Quick Analysis feature in Excel 2013.
Viewers will learn how to share Excel data with others from desktop Excel, as well as Excel Online via OneDrive, and embed an Excel file on a website.

776 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