How to add character after the last word written on the line

1

Dear Community,

I have a doubt that I have tried everything, but I can not solve it.

I have a list of ex names;

José Mario da Silva
Mariana Cristina
William Caio
Jorge Luiz Campos de Silva Andrade

In case there are more than 2,000 names ... what I have to do is after the last typed word I have to put 50 character empty and after the last empty "" insert 15 more character "000000000000000" ... to insert I was using the following ex formula:

=CONCATENAR(A1;"                        ";"000000000000000")

My big problem is that the lines are getting misaligned, because each name has an amount of character ... in case it should look like this:

José Mario da Silva                      000000000000000
Mariana Cristina                         000000000000000
William Caio                             000000000000000
Jorge Luiz Campos de Silva Andrade       000000000000000

But it's getting like this:

José Mario da Silva                      000000000000000
Mariana Cristina                     000000000000000
William Caio                   00000000000000
Jorge Luiz Campos de Silva Andrade                   000000000000000

Someone could help me in this case, because I do not know but what to do.

    
asked by anonymous 29.09.2017 / 18:05

3 answers

0

Excel Formula

With extra reference cell

Enter this formula in some cell =MÁXIMO((NÚM.CARACT($A:$A))) , for example Z1 and press Ctrl + Shift + Enter (remember to select each cell and pressing the buttons after inserting arrays into formulas, for example A: A)

And use this formula: =A1&REPT("*";($Z$1-NÚM.CARACT(A1))+50)&"000000000000000"

No extra reference cell

Or without Z1 =A1&REPT("*";(MÁXIMO((NÚM.CARACT($A$1:$A$2000)))-NÚM.CARACT(A1))+50)&"000000000000000" However, I suggest using the previous formula, since you only need to press Ctrl + Shift + Enter on reference cell Z1

This is the result, changing the font, for a monospace font can be previewed, changed to * to see better. In the tests only 15 asterisks are placed

ExcelVBA

EnterformulaandautofillbyVBA

AssumingthedataincolumnAandthenewdatainB,enterthedesiredformulainB1andrunthiscodeforAutofillinB.

lrA=Planilha1.Range("A" & Rows.Count).End(xlUp).Row 
Planilha1.Range("B1").AutoFill Destination:=Planilha1.Range("B1:B" & lrA)

VBA

I was going to make a code, but I did not even do it with Excel formula the problem has already been solved. But if you want, the same logic is done in VBA. The Len and loops function can be used. And to write a .txt, this link

    
29.09.2017 / 19:10
1

Check what is the longest name length you have in your table and replace the number 50 of that formula with it.

A1 is the cell where the names are written, in my example:

=CONCATENAR(A1;REPT(" ";50-NÚM.CARACT(A1));"!00000000000000")

I do not excel with this formula it does not look right, but if I copy the contents of the cells and paste them into a text editor with non-variable characters,

    
29.09.2017 / 18:43
0

I tried each of the above codes, they worked but anyway, I do not know why when I inserted txt they were misaligned.

After some time breaking the head and with the help of the programmer Anderson, we arrive at this code that meets all specifications;

Option Explicit

Sub Macro2()

Dim iArq As Long
Dim NOME As String
Dim op As Variant
Dim linha As Long
Dim resposta As String
   
linha = 1
While ThisWorkbook.Sheets("Concluidos").Cells(linha, 1) <> ""

NOME = ThisWorkbook.Sheets("Concluidos").Cells(linha, 1)
      
While Len(NOME) < 50
           
NOME = NOME + " "
            
Wend
NOME = NOME & "000000000000000"
       
iArq = FreeFile

Open fileELEB For Append As iArq

Print #iArq, NOME

Close #iArq
linha = linha + 1
Wend
    
MsgBox "O arquivo foi exportado com sucesso! ", vbInformation, "Exportar arquivos"

resposta = MsgBox("Você gostaria voltar ao menu?", vbYesNo + vbQuestion, "QNIS - CAIXA")
    
If resposta = vbYes Then

    
Else

Workbooks("QNIS V3.xlsm").Close False
Unload FormQNIS
End If

End Sub

I want to thank everyone for help, thank you very much!

    
01.10.2017 / 21:08