Vba Auto Increment File Name Changer

Posted on
Vba Auto Increment File Name Changer Average ratng: 4,1/5 8025 votes

I am trying to create a dynamic number of variables in VBA based on the value in a cell.Essentially what I'd like to end up with is something like Team1, Team2... to TeamX.Any help is greatly appreciated

  1. Excel Vba Increment Row
reggie86reggie86

Produce an incremental suffix for a filename e.g. File-1.xls, file-2.xls etc. 'C: AAA ' 'Change to suit strFileName = 'Data' 'Change to suit strExt = '.xls' 'Change to.

Excel Vba Increment Row

2 Answers

A dictionary would probably help in this case, it's designed for scripting, and while it won't let you create 'dynamic' variables, the dictionary's items are dynamic, and can serve similar purpose as 'variables'.

Later, to query the values, just call on the item like:

Dictionaries contain key/value pairs, and the keys must be unique. Assigning to an existing key will overwrite its value, e.g.:

You can check for existence using the .Exist method if you need to worry about overwriting or not.

Vba increment for loop

You can get the number of items in the dictionary with the .Count method.

Vba Auto Increment File Name Changer

A dictionary's keys must be integer or string, but the values can be any data type (including arrays, and even Object data types, like Collection, Worksheet, Application, nested Dictionaries, etc., using the Set keyword), so for instance you could dict the worksheets in a workbook:

Vba
David ZemensDavid Zemens

This will get you started. But before you start I recommend watching these WiseOwlTutorials tutorial on Youtube:

user6432984

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