• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

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

I want to use a VBA module to replace all Excel cell content in a range except for cells begining with specfic text.
0
AMixMaster
Asked:
AMixMaster
1 Solution
 
Ken ButtersCommented:
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
 
AMixMasterAuthor Commented:
This elusive bit of code worked absolutely perfect!
Thanks Ken!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now