Changing Cell Value Based on Another Cell Text - NOOB :(

yazanibrahim1984

New Member
Joined
May 16, 2019
Messages
10
Hello,

I'm super noob/beginner with macros and I'm writing a code to change the value for cells in column E to 0.00 if cells in column K has "Yes". Here's what I have:


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$K$" And Target.Value = "Yes" Then
Range("$E$").Value = "0.00"
End If
End Sub


But this doesn't work because:

1. it's only working on one cell
2. if I remove the word "Yes" from the cell in column K, the value remains 0.00 in column E and I cannot UNDO/Ctrl+Z to go back to the original value.

Any help/suggestion is appreciated.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello,

I'm super noob/beginner with macros and I'm writing a code to change the value for cells in column E to 0.00 if cells in column K has "Yes". Here's what I have:


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$K$" And Target.Value = "Yes" Then
Range("$E$").Value = "0.00"
End If
End Sub

("$E$")
and
"$K$"

don't put them like that
for E you need to put the row number for example
Range("E1") if row 1 or Range("E1") if row 2
And do the same thing for K put the row number
 
Upvote 0
Try this:

Code:
Sub ChangeColE()
Dim LR As Long
Dim i As Integer
LR = Cells(Rows.Count, "K").End(xlUp).Row
For i = 1 To LR
If Cells(i, 11) = "Yes" Then
  Cells(i, 5) = 0
  Cells(i, 5).NumberFormat = "0.00"
Else
End If
Next
End Sub
 
Upvote 0
Suggestion 1 didn't work (Can you write the full code)

Suggestion 2, Excel kept crashing & will not auto run :(

The code posted by kweaver works fine for me, just go to excel hit F11 and past it into a normal module, and then when you run it it will update the cells for you
How many rows of data do you have?
Are you posting it in the Worksheet page or in a module?

ABCDEFGHIJK
1xxxx0.00xxxxxYes
255550.0055555Yes
35555555555No
455550.0055555Yes
555550.0055555Yes
655550.0055555Yes
755550.0055555Yes
855550.0055555Yes
955550.0055555Yes
10####0.00#####Yes

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
I'll see if I can find a worksheet even for something like this
 
Last edited:
Upvote 0
Suggestion 1 didn't work (Can you write the full code)

Suggestion 2, Excel kept crashing & will not auto run :(

You can try this. I'm not well versed in worksheet events, so if anyone sees that i'm doing something stupid in this let me know.

This one is working for me. Just right click the sheet you want to use this on and click view code. Make sure it's pasted into the worksheet and not a module or else it won't work.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)


If Not Intersect(Target, Range("K1").End(xlDown)) Is Nothing Then Exit Sub


Dim LR As Long
Dim i As Integer
LR = Cells(Rows.Count, "K").End(xlUp).Row
For i = 1 To LR
If Cells(i, 11) = "Yes" Then
  Cells(i, 5) = 0
  Cells(i, 5).NumberFormat = "0.00"
Else
End If
Next
End Sub
 
Last edited:
Upvote 0
Quick update... The code is actually working, but it's case sensitive.


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)


If Not Intersect(Target, Range("K1").End(xlDown)) Is Nothing Then Exit Sub

Dim LR As Long
Dim i As Integer
LR = Cells(Rows.Count, "K").End(xlUp).Row
For i = 1 To LR
If Cells(i, 11) = "Yes" Then
Cells(i, 5) = 0
Cells(i, 5).NumberFormat = "0.00"
Else
End If
Next
End Sub


However, I noticed that I cannot Go Back (Ctrl Z) once I type "Yes", is there a way to correct it in the macro command?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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