Tengo la siguiente rutina para crear un archivo plano de mi hoja, se supone que debe tomar las filas que tienen datos pero siempre me toma la totalidad de las filas de la hoja, ¿qué puede estar sucediendo?
Sub CreaTXT()
Dim NombreArchivo, RutaArchivo, lcDato As String
Dim obj As FileSystemObject
Dim tx As Scripting.TextStream
Dim Ht As Worksheet
Dim i, j, nFilas, nColumnas, lnFilas As Integer
NombreArchivo = "PlanoFE"
RutaArchivo = ActiveWorkbook.Path & "\" & NombreArchivo & ".csv"
Set Ht = Worksheets("Datos")
Set obj = New FileSystemObject
Set tx = obj.CreateTextFile(RutaArchivo)
nColumnas = Ht.Range("A4", Ht.Range("A4").End(xlToRight)).Cells.Count
nFilas = Ht.Range("A5", Ht.Range("A5").End(xlDown)).Cells.Count
'lnFilas = ActiveSheet.Range("A5").End(xlDown).Cells.Count
For i = 1 To nFilas
For j = 1 To nColumnas
tx.Write Ht.Cells(i + 1, j).Value
If j < nColumnas Then tx.Write ";"
Next j
tx.WriteLine
Next i
tx.Close
Set obj = Nothing
MsgBox "El archivo se ha generado con exito..."
End Sub
Esta parte es la que me debe tomar la totalidad de las filas desde A5 hasta la última con dato pero me toma todo:
nFilas = Ht.Range("A5", Ht.Range("A5").End(xlDown)).Cells.Count