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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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
 
Upvote 0
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
 
Upvote 0
Nope, no marking as solved. A simple thank you is enough. :)
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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