replace cell contents with a word VBA

tintin1012000

Board Regular
Joined
Apr 27, 2011
Messages
237
OK a bit of a strange request

I need to replace the contents in a cell

example
type in ''123'' into cell A1. and replace this with the word ''passed'' when another cell is selected.

''123'' kinda acts as a password
in practice i will use more complex passwords and have a list of passwords that have different words associated
eg
123 = Passed
321 = Failed
456 = Redo Test
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You can only do that with coding. Which cell/ range of cells are the ones you want to change?
 
Upvote 0
Hi. Try this in the sheet module:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Rng as Range, c as Range

Set Rng = Intersect(Target, Range("F1:F99"))

If Not Rng Is Nothing Then
    For Each c In Rng
        Select Case c.Value
            Case 123
                c.Value = "Passed"
            Case 321
                c.Value = "Failed"
            Case 456
                c.Value = "Redo Test"
        End Select
    Next
End If
    
End Sub
 
Upvote 0
steve

thanks a million, that works perfect.




Hi. Try this in the sheet module:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Rng as Range, c as Range

Set Rng = Intersect(Target, Range("F1:F99"))

If Not Rng Is Nothing Then
    For Each c In Rng
        Select Case c.Value
            Case 123
                c.Value = "Passed"
            Case 321
                c.Value = "Failed"
            Case 456
                c.Value = "Redo Test"
        End Select
    Next
End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,189
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top