Сначала удалите «-», наберите номер, наберите 10 цифр и сохраните данные. Использование функции форматирования. Затем вы можете отформатировать ячейку как текст и переместить данные в ячейку. Это можно сделать с помощью vba.
'HERE I RUN THE FORMAT FORMULAS
Dim rngDB As Range
Dim vDB As Variant, i As Long, r As Long
planillaDestino.Range("B2:B" & filaIndiceDestino).Formula = "=CONCAT(YEAR(L2),IF(INT(MONTH(L2))<10,0,""""),MONTH(L2))" ' per pro
Set rngDB = planillaDestino.Range("B2:B" & filaIndiceDestino)
vDB = rngDB
r = UBound(vDB, 1)
For i = 1 To r
vDB(i, 1) = Replace(vDB(i, 1), "-", "")
cnt = 10 - Len(vDB(i, 1))
s = WorksheetFunction.Rept("0", cnt) 'if letters inside
'vDB(i, 1) = Format(vDB(i, 1), "0000000000") ' if number
Next i
rngDB.NumberFormatLocal = "@" '<~~ text format
rngDB = vDB
Весь код
Private Sub duplicadorLicMed()
Set Application = CreateObject("Excel.Application")
Dim planillaDestino As Worksheet
Set planillaDestino = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
planillaDestino.Name = "hojaDest"
Dim planillaFuente As Worksheet
Set planillaFuente = Application.Workbooks.Open("tstfl.xlsm")
Set planillaFuente = ThisWorkbook.Worksheets(1)
planillaFuente.Name = "hojaFuente"
Dim filaFuenteUltima As Long
filaFuenteUltima = planillaFuente.Cells(planillaFuente.Rows.Count, "B").End(xlUp).Row
Dim filaIndiceFuente As Long
Dim filaIndiceDestino As Long
filaIndiceDestino = 1 ' salto de lineas y encabezado
Dim fechaInicio As Variant
Dim fechaFin As Variant
Dim fechaIndice As Date
For filaIndiceFuente = 2 To filaFuenteUltima
fechaInicio = planillaFuente.Cells(filaIndiceFuente, "L").Value
fechaFin = planillaFuente.Cells(filaIndiceFuente, "M").Value
' VALIDATOR OF DATA
For fechaIndice = fechaInicio To fechaFin
filaIndiceDestino = filaIndiceDestino + 1
' ROWS GET REPEATED HERE
Next fechaIndice
Next filaIndiceFuente
'HERE I RUN THE FORMAT FORMULAS
Dim rngDB As Range
Dim vDB As Variant, i As Long, r As Long
Dim cnt As Integer
planillaDestino.Range("B2:B" & filaIndiceDestino).Formula = "=CONCAT(YEAR(L2),IF(INT(MONTH(L2))<10,0,""""),MONTH(L2))" ' per pro
Set rngDB = planillaDestino.Range("B2:B" & filaIndiceDestino)
vDB = rngDB
r = UBound(vDB, 1)
For i = 1 To r
vDB(i, 1) = Replace(vDB(i, 1), "-", "")
cnt = 10 - Len(vDB(i, 1))
s = WorksheetFunction.Rept("0", cnt) 'if number & string
'vDB(i, 1) = Format(vDB(i, 1), "0000000000") ' if number
Next i
rngDB.NumberFormatLocal = "@" '<~~ text format
rngDB = vDB
'planillaDestino.Range("B2:B" & filaIndiceDestino).Formula = "=CONCAT(IF(LEN(SUBSTITUTE(C2,"-","") )<9,"00","0"),SUBSTITUTE(C2,"-","") )" ' digitador rut
planillaDestino.Range("K2:K" & filaIndiceDestino).Formula = "=ABS(DAYS(L2,M2))+1" ' dias totales
MsgBox "PROCESO COMPLETO"
' End If
End Sub