Increment Cell Value

JamesA11

New Member
Joined
Oct 2, 2020
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I have been using a simple macro (below) to increase the value of cell B3. My spreadsheet is getting more complex and I need to adapt the macro so that it increments the previous cell on the row if there is a 1 in next cell.

So, in column C I have a range C8:C33 where a user can input a value. If they input a 1 the preceding cell should increment by 1. Eg. if a user inserts 1 in cell C10, the macro should increment cell B10 by 1.

Is this possible with VBA?

Thanks

VBA Code:
Sub increment()
ThisWorkbook.Worksheets("Count").Range("B3").Value = Range("B3").Value + 1
    
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Right click on tab name/Viewcode then paste below code into:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C8:C33")) Is Nothing Then Exit Sub
Target.Offset(0, 1).Value = Target.Offset(0, 1) + Target' Target.Offset(0, 1).Value = Target.Offset(0, 1) + 1 if donot want to add C10 value, just 1
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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