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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Video by: Zack
Viewers will learn about using Excel in a browser with Excel Online.
Viewers will learn a basic relationship technique in Power Pivot for Excel 2013.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now