Double click to increment dates in a table

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
Using the Worksheet_BeforeDoubleClick event, and referencing column "Date" in "Table1", how can I increment dates by one month?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
It's easier when you tell us what column.
Like column "B" or column "D"

How are we to know what column is Column "Date"
Try this assuming we are dealing with column "D"

If not modify script:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("[COLOR=#ff0000]D:D[/COLOR]")) Is Nothing Then
Cancel = True
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Target.Value = DateAdd("m", 1, Target.Value)
End If
End Sub
 
Last edited:
Upvote 0
Thank you; but I was hoping to be able to reference the name of the column to save having to update the script when I change the table.
 
Last edited:
Upvote 0
Are you saying the Column has been Named "Date".

How are we to know what column is column "Date"?
You have to give me some way of knowing what column is column "Date"

Thank you; but I was hoping to be able to reference the name of the column to save having to update the script when I change the table.
 
Upvote 0
Do you want to only increment the date that has been clicked in the column or the entire column?

If it's the former try this.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim tbl As ListObject
Dim rngDateCol As Range

    Set tbl = Me.ListObjects("Table1")
    
    Set rngDateCol = tbl.ListColumns("Date").DataBodyRange
    
    If Not Intersect(Target, rngDateCol) Is Nothing Then
    
        Cancel = True
        
        Target.Value = DateAdd("m", 1, Target.Value)

    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,729
Members
449,049
Latest member
MiguekHeka

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