when a value manually changes in a cell, another cell should pick a value based on conditions

leejoos

New Member
Joined
Sep 14, 2017
Messages
5
Hi There,

I have a riddle to solve! In a sheet, I need to get changed the data in cell G27 whenever I change a value in F27 based on the conditions specified. The conditions are, if the value in F27 is >10, then G27 should show
±0.2 , if F27 is in between 6 - 10, then
±0.15, if F27 is in between 3 -6, then
±0.10 and if F27 id <3, then
±0.05. Can someone help me to solve this with VBA? I am just a newbie in VBA!

Best Regards,


<tbody>
</tbody>

<tbody>
</tbody>

<tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hello Liju,

If this is to work on the same sheet as per your previous thread, then change the previous code to the following:-
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Call ChangeEvent1(Target)
Call ChangeEvent2(Target)

End Sub

Private Sub ChangeEvent1(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("F29")) Is Nothing Then Exit Sub
Range("F4:F5").Value = Range("F31:F32").Value

End Sub

Private Sub ChangeEvent2(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("F27")) Is Nothing Then Exit Sub

If Range("F27").Value > 10 Then Range("G27").Value = "±0.20"
If Range("F27").Value > 6 And Range("F27") < 10 Then Range("G27").Value = "±0.15"
If Range("F27").Value > 3 And Range("F27") < 6 Then Range("G27").Value = "±0.10"
If Range("F27").Value < 3 Then Range("G27").Value = "±0.05"

End Sub

This should take care of both events for you. The Worksheet_Change event should now call either of the event changes independently.

I hope that this helps.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,287
Members
449,149
Latest member
mwdbActuary

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