
Originally Posted by
macro_noob
Hello,
My want:
Is there any way I can have the macro -
1. Point to the .txt file (no problem here)
2. Then, extract or pull that row/line count number
3. Test that number if it over x amount of lines
4. And then end with IF over X amount, then...
5. Or, IF under X amount, then...
Any tips would be great! Thanks!!!
try
Sub test()
Dim fn As String, temp As String, x, i As Long, ii As Long, y
Dim delim As String, t As Long, a(), n As Long, maxCol As Long
fn = "c:\test.txt" '<- file path
delim = vbTab '<- delimitter
temp = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
x = Split(temp, vbCrLf)
MsgBox "There are " & UBound(x) + 1 & " lines"
ReDim a(1 To 65000, 1 To 100)
For i = 0 To UBound(x)
n = n + 1
y = Split(x(i), delim)
For ii = 0 To UBound(y) : a(n,ii + 1) = y(ii) : Next
myxCol = Application.Max(maxCol, ii - 1)
If n = 65000 Then
Sheets(t).Range("a1").Resize(n, maxCol).Value = a
n = 0 : maxCol = 0 : t = t + 1 : ReDim a(1 To 65000, 1 To 100)
End If
Next
If n > 0 Then Sheets(t).Range("a1").Resize(n, maxCol).Value = a
End Sub
Bookmarks