Incrament a different cell with a macro.

Twill

New Member
Joined
May 18, 2016
Messages
2
I'm working on an inventory spreadsheet where the item's names are listed in column A, their ID number in column B, and the current number in inventory in column C. I have macro buttons for incrementing and decrementing the values in column C, but they only work when the cell in column C is selected. Is there a way to increment and decrement the cell in column C that is in the same row as the currently selected cell?

Code:
Sub IncramentFull()
    ActiveCell.Value = ActiveCell.Value + 1
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the Board!

Try:
Code:
Sub IncramentFull()
     Cells(ActiveCell.Row,"C").Value =Cells(ActiveCell.Row,"C").Value + 1
End Sub
 
Upvote 0
Use the .offset to do so.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("a1:a10")) Is Nothing Then
        Target.Offset(0, 2).Value = Target.Offset(0, 2).Value + 1
    End If
End Sub

This will add 1 to the value in cell C3 when you change the focus to cell A3.
The 'Intersect' part handles which cells will start the code ones they get the focus. In this case only cells A1 to A10 will activate this piece of code.
 
Upvote 0
I guess we never established if you want this to run automatically or not. My code is just a variation of your original code that would be run manually. WinteE's code will run automatically, but anytime a cell in the range A1:A10 is selected. If you want it to run automatically, but only if a cell in range A1:A10 is changed, then you would use the "Worksheet_Change" event instead of "Worksheet_SelectionChange".
 
Upvote 0
Thanks so much for the help! I could find ways to alter the active cell based on offsets, but no way to say "always go to this column". I probably should have mentioned that at the moment I do have it set to run on a button press. I apologize for the confusion. Thanks again for the help!
 
Upvote 0

Forum statistics

Threads
1,216,172
Messages
6,129,290
Members
449,498
Latest member
Lee_ray

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