Automatic next cell numbering for Bespoke number style

S_Coupland

Board Regular
Joined
May 14, 2012
Messages
64
Hi All, Good Morning (Evening)

I am trying to work out how to automaticaly fill in the next number in a sequence of bespoke numbers like this in column B 1012-0153-70, next 1012-0153-71, next 1012-0153-72 and so on so when i click on the next open cell in column B it adds the next number in the sequence

I have the following VBA code in my Sheet:

Private Sub Worksheet_SelectionChang()
With Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
If Target.Address = .Address Then
.Offset(-1, 0).AutoFill Destination:=.Offset(-1, 0).Resize(2, 1), Type:=xlFillDefault
End If

End With

but nothing seems to work. i also have the following VBA code on the same sheet:


Private Sub ComboBox1_Change()
End Sub
Private Sub Calendar1_Click()
ActiveCell.Value = CDbl(Calendar1.Value)
ActiveCell.NumberFormat = "dd/mm/yyyy"
ActiveCell.Select
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("A5:A10000"), Target) Is Nothing Then
Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
Calendar1.Top = Target.Top + Target.Height
Calendar1.Visible = True
' select Today's date in the Calendar
Calendar1.Value = Date
ElseIf Calendar1.Visible Then Calendar1.Visible = False
End If
End Sub
Private Sub Worksheet_SelectionChang()
With Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
If Target.Address = .Address Then
.Offset(-1, 0).AutoFill Destination:=.Offset(-1, 0).Resize(2, 1), Type:=xlFillDefault
End If

End With


is it because the two codes are conflicting in any way?

Many Thanks

Simon
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,696
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You can't have two selectionchange event codes in one sheet (and the declaration for the second is wrong anyway). You need to combine the processing code into one routine:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Not Application.Intersect(Range("A5:A10000"), Target) Is Nothing Then
        Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
        Calendar1.Top = Target.Top + Target.Height
        Calendar1.Visible = True
        ' select Today's date in the Calendar
        Calendar1.Value = Date
    ElseIf Calendar1.Visible Then
        Calendar1.Visible = False
    End If
    With Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
        If Target.Address = .Address Then
            .Offset(-1, 0).AutoFill Destination:=.Offset(-1, 0).Resize(2, 1), Type:=xlFillDefault
        End If
    End With
End Sub
 

S_Coupland

Board Regular
Joined
May 14, 2012
Messages
64
Hi Rory,

Many Thanks AGAIN :biggrin:..... twice in one day...... Works perfectly, thought it was a code conflict.....

Do I Have To Show These Treads As Solved? ....... If So How?

Many Thanks

Simon
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,696
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Nope, no marking as solved. A simple thank you is enough. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,129,357
Messages
5,635,797
Members
416,882
Latest member
ericvrealty

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
Top