Increase Cell Value By 1 If Another Cell Value =

Lewzerrrr

Active Member
Joined
Jan 18, 2017
Messages
256
Hi,

I've searched around for this but can't come to a solid answer.. know it's probably very simple.

I need a code that when the cell in S4 changes to "27" then +1 in S3.

Never mind, figured it out lol

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("S4")) Is Nothing Then Exit Sub


If Range("S4").Value = "27" Then
    Range("S3").Value = Range("S3").Value + 1
End If


End Sub

Any help would be appreciated,

Thanks,
 
Last edited:

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
It maybe you need the Calculate event, try:
Code:
Private Sub Worksheet_Calculate

If Range("S4").Value = 27 Then Range("S3").Value = .Range("S3").Value + 1

End Sub
OR in your original code, try changing "27" to 27, i.e. a numerical value rather than a string.
 
Upvote 0
It maybe you need the Calculate event, try:
Code:
Private Sub Worksheet_Calculate

If Range("S4").Value = 27 Then Range("S3").Value = .Range("S3").Value + 1

End Sub
OR in your original code, try changing "27" to 27, i.e. a numerical value rather than a string.

Thanks Jack, my code works :) yours is super simple, will remember for future ref
 
Upvote 0
You're welcome, but yours works because..? Ah missed the part
Never mind, figured it out lol

Mine's not "simpler", only that it's slightly different for a Worksheet_Calculate event than Worksheet_Change and for an IF statement in VBA, you can exclude End If Part, only if there's a single statement after THEN, e.g.
Code:
If Range("A1") = 1 Then
  Range("A2") = 2
End If
Can be written as:
Code:
If Range("A1") = 1 Then Range("A2") = 2
However:
Code:
If Range("A1") = 1 Then
  Range("A2") = 2
  Sheets(Range("A2")).Select
End If
Can't be reduced to a single line of code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,820
Messages
6,132,889
Members
449,768
Latest member
LouBa

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