I am trying to iterate an excel sheet through vba. I need it to read a sheet line by line to have an array with each cell, until it finds the empty (final) line.
I put an example of data:
I know there will be data from column A to G, what I don't know is the number of lines there will be.
The idea is:
Sub importarDatos()
'
' importarDatos Macro
'
'
Dim lineas As Worksheet
Set lineas = Worksheets("Lineas")
End Sub
I create a macro, which gets the sheet. (So far so good).
The question is: How can I get the data of that sheet into an Array from A1:G1 to An:Gn so that I can then iterate through that array with a loop?
I will need at a certain point to know the number of the line I am reading, to write the data to another sheet (export the data) on the same line. That is, each line of the sheet to be read will write 1 line to a new sheet.
PS: The sheet to read is in the location where I am going to execute the macro. In other words, by pressing a button (I know how to do that), it will call the macro that will read the sheet of that Workbook and import the data into another sheet.
Thanks in advance
And define the range up to column 7, pass it to the array, and then iterate through the array?
Loading a range into an array is hardly time consuming and iterating through it is the same. It depends on the number of rows you have, maybe it's worth it.
It seems that the solution was not very difficult.
Searching the internet, I realized that I could get the last line written, therefore, from there, I can make a loop to get each of the lines as follows:
The most optimal thing would be to fetch up to column 7, so as not to fetch the entire file every time you read a line. We would have to see how to do that.