Custom Format

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi,

How could I format the cell to make it appear as A4AM0000?

Suppose if the user writes A4AM0001 the format will change from A4AM0000 to A4AM0001.

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If you mean you want to input a number and have the cell display A4AM plus a four digit number based on the input number then format the cell :-

"A4AM"000#
 
Upvote 0
Thanks for the help. But how could I make a code that would change the numbers on serial basis?
 
Upvote 0
Thanks for the help. But how could I make a code that would change the numbers on serial basis?

Do you mean you want to use VBA to incease the four digit number at the end by 1 ?

If so, when do you want the number changed and by what means?

Are you looking for a sequential numbering method for a Template?

Please provide more info on what you are trying to do.
 
Upvote 0
Yes, I meant I want to increase the four digit number at the end by 1. And I want the number to be changed when the user runs the macro.

Suppose if the user writes A4AM0001 the format will change from A4AM0000 to A4AM0001.

And yes I'm looking for a sequential numbering method for a Template.

I hope I've made my question clear.

Thanks in advance.
 
Upvote 0
"Suppose if the user writes A4AM0001 the format will change from A4AM0000 to A4AM0001."

I don't know what this means. Do you want the number to be changed by a macro, or do you want the user to change it manually?

I will assume that :

- You are using XL2003 or earlier
- You have a template (.xlt) from which you create workbooks (.xls)
- the workbooks will be numbered sequentially
- the number of each workbook will be displayed in cell A1
- you want the number of each workbook to be entered by a macro
- the user cannot alter or change a number once it has been entered

Based on these assumptions, format A1 as explained in my earlier post, and then :-

1. To enter the next sequential number in A1

Code:
Sub Insert_Next_SeqNbr()
Dim Nbr As Long
Nbr = GetSetting("XLInvoices", "Invoices", "NextNbr", 1)'If you want to start at some number other than 1, amend accordingly
If Right(ThisWorkbook.Name, 4) = ".xls" Then
    With Sheets("Sheet1") 'Change sheet name as required
        If .[A1] = "" Then 'Amend cell ref as required
            Application.EnableEvents = False
            .[A1] = Nbr 'Amend cell ref as required
            Application.EnableEvents = True
            SaveSetting "XLInvoices", "Invoices", "NextNbr", Nbr + 1
        End If
    End With
End If
End Sub

This macro could be run from a worksheet button, or called from an event procedure (e.g. Workbook_BeforeSave).


2. To prevent a user from manually entering or changing the number in A1, put this in the sheet module :-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [A1]) Is Nothing Then 'Amend cell ref as required
    With Application
        .EnableEvents = False
        .Undo
        .EnableEvents = True
    End With
End If
End Sub


3. To reset the sequential numbering to 0000


Code:
Sub Delete_SeqNbr_Registry_Entry()
On Error Resume Next
DeleteSetting "XLInvoices", "Invoices"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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