07.09.2019»»суббота

Vba Auto Increment File Name Converter

07.09.2019
    31 - Comments

One method...............save a sequential number in the Registry then when you open a new workbook from the Template it is immediately saved as template name + sequential number pulled from the Registry

Example code for Thisworkbook module of an Excel template named MyTemplate.

NOTE: MyTemplate must be saved as macro-enabled template (*.xltm)

I have an application that generates csv files. Each file is date stamped. Eg: 10092005.csv 11092005.csv 11092005.csv 12092005.csv etc. I would like to add an incrementing number to the end of each filename, with the most recent filename being the last filename number + 1, so the above should look.

Private Sub Workbook_Open()
Const sAPPLICATION As String = 'Excel'
Const sSECTION As String = 'MyTemplate'
Const sKEY As String = 'MyTemplate_key'
Const nDEFAULT As Long = 1&
Dim nNumber As Long
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY, nDEFAULT)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs sSECTION & Format(nNumber + 1&, '_0000')
Application.DisplayAlerts = True
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End Sub

The first new workbook will be saved as Excel workbook MyTemplate_0001.xlsx then increment from there.........probably no need to have it as macro-enabled. If you did need the copy saved as macro-enabled post back for revised code to saveas macro-enabled and prevent Workbook_Open from running when copies are opened later for review.

Gord

Active9 months ago

I have strings in Excel like AA or XA.

Vba Auto Increment File Name Converter Software

I need to increment them like this:

For AA in cell A1, it will be AB in cell B1, AC in cell B2 and so on.

For XA in cell A1, it will be XB in cell B1, XC in cell B2 and so on.

I tried the popular code =CHAR(CODE(A1)+1) but it does not work after Z.

Any hints are welcome.

Vba Auto Increment File Name ConverterExcellll
11.4k7 gold badges42 silver badges64 bronze badges
Andy KAndy K

Vba Increment Number By 1

1951 gold badge3 silver badges21 bronze badges

11 Answers

Try this: put 'AA' into cell A1 and enter the following formula into cell B1 and drag across

It will increment as follows: AA, AB, AC,..., AZ, BA, BB, BC.... etc

You might want to adapt this formula to suit your particular presentation. Please note that this won't work past 'ZZ'.

Update: fixed bug

CallumDACallumDA

We can use the excel spreadsheet itself to help increment the letters - the increment will work from A to XFC

First create the cell reference: INDIRECT(A1&'1')
Then find the address of the next column over: ADDRESS(1,COLUMN(INDIRECT(A10&'1'))+1)

Then from the $??$1 we extract the letters: 2 ways:

  1. Look for the second $, and snip the text out between them

  2. Replace the 1 and $ with nothing in the string

Choose which one works best for you

SeanCSeanC
3,3942 gold badges15 silver badges26 bronze badges

Another example: Type this into cell A1, then copy the formula to any or all cells.

Intended as an example of how one may think about the problem.

HannuHannu
4,5721 gold badge11 silver badges25 bronze badges

This will reset to 'A' when it reaches 'Z'

You can build out beyond that with more if statements.

OR

I just wrote this formula for something similar:

Andy K
1951 gold badge3 silver badges21 bronze badges
Nick FleetwoodNick Fleetwood

As another solution for it with using ADDRESS() is:

Above formula will return AA in first row and AB in second row and so on.

Also with using math the formula is:

shA.tshA.t

I used this code to obtain Cell address

This example is for AT17 cell address.

Increment you define how many numbers you will increment

I wrote this code in cell Ax17.

Later I obtained value of AT17 with

Done !!!

Now you can increment columns instead of rows !!!

fixer1234
22.1k14 gold badges55 silver badges89 bronze badges
Mark TwainMark Twain
IvanoffIvanoff

Fill Column A (from row 1) with consecutive numbers starting with 0 to 100 [or till requirement]

Fill Cell B1 with below formula

Copy down the formula from B1 to other rows in Column B [till the row you have filled Column A]

This works for 3 characters AAA to ZZZ

Formula needs to be modified as per no. of characters required (AA to ZZ / AAAAA to ZZZZZ / etc)

SundarSundar

I know this is slightly off the main question, but I think it answers the fuller question...If you have a letter in A1, and you wish it to be stepped by a number in B1, the following formula combo will achieve it from single letters to ZZ.

Copy it down the column and the results are there. Change the B5 number and the results change.

Vba increment variablePierre.Vriens
1,2876 gold badges13 silver badges19 bronze badges
Graham PorterGraham Porter

Vba Auto Increment File Name Converter Pdf

user380375
user560874user560874

For Columns, the below is the right solution.

=IF(LEN(ADDRESS(1,COLUMN()))=4,MID(ADDRESS(1,COLUMN()),2,1),MID(ADDRESS(1,COLUMN()),2,2))

user2459372user2459372

Not the answer you're looking for? Browse other questions tagged microsoft-excel or ask your own question.

 fullpacviva © 2019