Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
Does anyone know of a way to increment hyphenated numbers using VBA, a Max formula or any other formula in Excel?
Example: 10000-1 increments to 10000-2 and so on. For my purposes, the first 5 digits do not increment. Only the numbers after the hyphen.
If I put 10000-1 in a cell and drag the handle down, Excel increments the number the way I'd like. However, if I try to use VBA to do the same thing, I get a type mismatch error. If I try to use the Max formula, I get an error.
.Range("A2").Value = .Range("A2").Value + 1 results in the type mismatch error.
.Range("A2").Value = Left(.Range("A2").Value, 6) & 1 + Right(.Range("A2").Value, 1) seems to increment but only up to 10 and then goes back to 1.
I would need the number after the hyphen to increment into the hundreds if possible. TBH, it would be fantastic if the number could be presented as 10000-001 and still increment one digit at a time but everything I've tried only results in the zeroes after the hyphen disappearing.
Example: 10000-1 increments to 10000-2 and so on. For my purposes, the first 5 digits do not increment. Only the numbers after the hyphen.
If I put 10000-1 in a cell and drag the handle down, Excel increments the number the way I'd like. However, if I try to use VBA to do the same thing, I get a type mismatch error. If I try to use the Max formula, I get an error.
.Range("A2").Value = .Range("A2").Value + 1 results in the type mismatch error.
.Range("A2").Value = Left(.Range("A2").Value, 6) & 1 + Right(.Range("A2").Value, 1) seems to increment but only up to 10 and then goes back to 1.
I would need the number after the hyphen to increment into the hundreds if possible. TBH, it would be fantastic if the number could be presented as 10000-001 and still increment one digit at a time but everything I've tried only results in the zeroes after the hyphen disappearing.