3
I’ll try to summarize what I’m trying to do:
I made a userform so that my user inserts data that will feed a table, he can put "n" information and the table will form according to the volume of data he fills.
After that, when it finishes and click on END, I want another userform to open on the screen with a sentence concatenating the data that was entered, following a predetermined logic.
For example, after the inputs the spreadsheet looked like this:
What I want is for my next userform to bring the following concatenated:
'Test' -x "1111|2|66","2222|2|77","3333|3,88","4444|3|99" -n
The terms I need to add with & I can, but I don’t know how to concatenate in this way the values of each column following the sequence and stopping to the point where there is no more information in the spreadsheet.
Another detail would be to have this separation by , between each concatenated
The section where I want to put the command to concatenate this is here:
Private Sub sair_click()
Dim parse As String
parse = "concatenado"
Unload Me
code.console = parse
code.Show
End Sub
(after it clicks on the END button "exit" opens my userform "code" with the variable "parse" that should have this result concatenated.
After using the presented solution I replaced the "sub Showwithmessage" for the call of my last Userform, as it met the required demand (it is expected that my user can copy the result to paste elsewhere). Maybe it’s some mistake I made, to illustrate it better, the expected sequence is as follows:
1º Userform: The user inserts the title, after clicking enter, another userform opens;
2º Userform: The user inserts the three information needed to fill the table columns as many times as needed (Clicking Enter after each fill). At the end of it click on END which brings the last Userform with a text box containing the concatenated result.
In this example I simulated the case where only one line was inserted by the user.
+---+------------------+----------------+-----------+
| | A | B | C |
+---+------------------+----------------+-----------+
| 1 | Nome da Planilha | Teste' | |
| 2 | Node da Aula | Tipo da Tarefa | Agrupador |
| 3 | "1111| | 2| | 66" |
| | | | |
+---+------------------+----------------+-----------+
3º Userform: As said above, the final result of inserting only one complete row in the table was this way:
The script of the "END" button is as follows, using the solution proposed in this topic:
Private Sub sair_click()
Dim parse As String
Dim ws As Worksheet
Dim UltimaLinhaPlanilha As Long, Linhas As Long, Colunas As Long
Set ws = ThisWorkbook.Sheets("ADAE")
UltimaLinhaPlanilha = ws.UsedRange.Rows.Count
parse = ws.Range("B1") & " -x "
For Linhas = 3 To UltimaLinhaPlanilha
For Colunas = 1 To 3
parse = parse & ws.Cells(Linhas, Colunas)
Next Colunas
If Linhas <> UltimaLinhaPlanilha Then parse = parse & ","
Next Linhas
parse = parse & " -n"
Unload Me
code.console = parse 'Aqui eu chamo o ultimo userform "code" com o que estará escrito dentro da caixa de texto "console" no caso a variável "parse"
code.Show
End Sub
It worked, great explanation! I appreciate the care in the work of detailing the explanation.
– Felipe Stenzel
After more tests, I came up with one more question. It worked normal for more than 3 filled lines. But 2 or 1 line only, the comma appears as well. For example: Test' -x "1111|2|66",, -n OU Test' -x "1111|2|66","2222|2|77", -n
– Felipe Stenzel
For me this error did not occur, you have more data in other columns of this tab/sheet?
– danieltakeshi
I edited my post with the details of what I modified and how is the complete cycle of my project to better illustrate the problem
– Felipe Stenzel
@Felipestenzel I performed the tests and it is working in mine, maybe the last line of the spreadsheet is not line 3, because there is more information in other columns. So instead of getting the last row of the sheet, try to get the last row of column A with:
UltimaLinhaPlanilha= ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
. For it seems that there is some value in line 5 and this causes the loop to be performed up to the 5, even when it is to go up to 3 or 4.– danieltakeshi
Now it worked perfectly, I think it should be the macro button I put to start the process, but with this new command worked, thanks again for the help!
– Felipe Stenzel