Quantcast
Channel: Active questions tagged worksheet-function - Super User
Viewing all articles
Browse latest Browse all 925

VBA: How to replace entire Excel cell value basing on its content?

$
0
0

I have an Excel Spreadsheet with some names in a cells. There can be as one name per cell as multiple names in one cell.

For example: Cell A5 contains "Joe", cell BD54 contains "Joe;Harry;Molly", cell YY1 contains "Harry;Butch".

What I wan to achieve is to replace values of all cells that contains "Joe" or "Molly" with "1, regardless of what else is in this cells, and celss that contains just "Harry" or "Butch" will be replaced with "0" if it does not contain "Joe" or "Molly". For example above, result should be as follows: A5 conains "1", BD54 contains "1", YY1 contains "0".

I'm a total newbie in VBA - would you, gents, please assis with that? I suspect that Cells.Replace should be used here, however, I'm not sure how to pass a list of names to it

Dim Findtext As String Dim Replacetext As String Findtext = "Joe","Molly" Replacetext = "1" Findtext = "Harry","Butch" Replacetext = "0" Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False 

Viewing all articles
Browse latest Browse all 925

Trending Articles