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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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