Double click to add number in cell above +1 in value

Avalanchez

New Member
Joined
Jun 23, 2021
Messages
17
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
Im looking for a way to when I put a number in say A1, any number at all, that when I click the cell below it it will add 1 to the value.

Example:
A1= 9547
i double click A2 and it now equals 9548

I know about auto fill and filling rows by dragging etc. I want this double click one at a time method though because for example the next number could skip and be 9550 but i still want to then go to 9551 after that.

Thanks for any help.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
How about this?

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Offset(-1).Value = Target.Offset(-1).Value + 1
Cancel = True
End Sub
 
Upvote 0
Hi,
Try this code in the sheet's VBA-module
VBA Code:
' Put the below code into sheet's module:
' Copy this code - Right Click on the sheet's tab - View code - Paste the code - Alt-Q

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column <> 1 Or Target.Row = 1 Then Exit Sub
  Target.Value = Target.Offset(-1).Value + 1
  Cancel = True
End Sub
 
Upvote 0
How about this?

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Offset(-1).Value = Target.Offset(-1).Value + 1
Cancel = True
End Sub
that just seems to be changing the number in A1 when i click A2.

The number in A2 should be A1 +1

Feels like ur in the right direction thanks.
 
Upvote 0
Hi,
Try this code in the sheet's VBA-module
VBA Code:
' Put the below code into sheet's module:
' Copy this code - Right Click on the sheet's tab - View code - Paste the code - Alt-Q

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column <> 1 Or Target.Row = 1 Then Exit Sub
  Target.Value = Target.Offset(-1).Value + 1
  Cancel = True
End Sub
Hey I think this works!, the only thing now is i have this code alreay in there for the date/ time how can i crunch this into there?


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F1:G22")) Is Nothing Then
Cancel = True
Target.Formula = Time

End If
If Not Intersect(Target, Range("A1:A22")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If

End Sub

Much appreciated
 
Upvote 0
Hey I think this works!, the only thing now is i have this code alreay in there for the date/ time how can i crunch this into there?


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F1:G22")) Is Nothing Then
Cancel = True
Target.Formula = Time

End If
If Not Intersect(Target, Range("A1:A22")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If

End Sub

Much appreciated
Also is there a way to make this column specific like i want column H and C to run the code you wrote only.
 
Upvote 0
Try this code then:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
 
  If Not Intersect(Target, Range("F1:G22")) Is Nothing Then
    Cancel = True
    Target.Formula = Time
  End If
 
  If Not Intersect(Target, Range("A1:A22")) Is Nothing Then
    Cancel = True
    Target.Formula = Date
  End If
 
  If Target.Row = 1 Then Exit Sub
  ' The 3 and 8 are the columns numbers for C and H accordingly
  If Target.Column = 3 Or Target.Column = 8 Then
    Target.Value = Target.Offset(-1).Value + 1
    Cancel = True
  End If
 
End Sub
 
Upvote 0
Solution
Instead of the code line: If Target.Column = 3 Or Target.Column = 8 Then
you can use this one as well: If Not Intersect(Target, Range("C:C,H:H")) Is Nothing Then
 
Upvote 0
Try this code then:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
 
  If Not Intersect(Target, Range("F1:G22")) Is Nothing Then
    Cancel = True
    Target.Formula = Time
  End If
 
  If Not Intersect(Target, Range("A1:A22")) Is Nothing Then
    Cancel = True
    Target.Formula = Date
  End If
 
  If Target.Row = 1 Then Exit Sub
  ' The 3 and 8 are the columns numbers for C and H accordingly
  If Target.Column = 3 Or Target.Column = 8 Then
    Target.Value = Target.Offset(-1).Value + 1
    Cancel = True
  End If
 
End Sub
That works perfect!

Thank you, you the man!
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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