0

In essence I have to develop an easy tallying system in Excel to make my main project easier.

All I want to be able to do is to click a cell (any cell in the Column B) and when I do that, the value within should be incremented by one.

I have tried using this code as a POC but it doesn't seem to be working.

I've done a reasonable amount of programming but have never tried to incorporate it into excel before so any help would be appreciated!

Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If IsNumeric(Target.Value) Then
    Target.Value = Target.Value + 1
    Application.EnableEvents = False
    Target.Resize(1, 2).Select
    Application.EnableEvents = True
    Cancel = True
End If

End Sub
ScottishTapWater
  • 3,656
  • 4
  • 38
  • 81
  • How isn't it working? It seems to work for me (note: I don't think you [need/want that `.Select` statement](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros)). Did you place it in the *worksheet* module of the sheet you want this to run on? – BruceWayne Jul 11 '16 at 16:04
  • When I double click on the cell, nothing appears to happen barring that cell being selected. I've gotten rid of the `select` statement and nothing seems to be changing. It's in `Module1` which is in the `Modules` folder, it needs to work with `Sheet1` which is in the `Microsoft Excel Objects` folder. Sorry if this is an incredibly basic question – ScottishTapWater Jul 11 '16 at 16:13

1 Answers1

1

You need to place the code in the Worksheet module of the sheet you want it to run on. Say you want it to run on "Sheet1", place it in the Sheet1 module:

enter image description here

enter image description here

(I commented out the .Select line, in my example above)

BruceWayne
  • 22,923
  • 15
  • 65
  • 110