Hello, how do I write a VBA code/formula to count the total number of populated columns in "closed" text tab delimited file? The sections in question are in red. Only seems to work for file information such as file name.
Rich (BB code):
Sub ListFiles()
On Error Resume Next
' Declarations
Dim Directory As String
Dim r As Long
Dim f As String
Dim FileSize As Double
Dim A As String
On Error Resume Next
' Assigning variables
Directory = Application.DefaultFilePath & "\Unzipped\"
r = 1
On Error Resume Next
' Insert field headers
Cells(r, 1) = "FileName" ' Column 1
Cells(r, 2) = "GetAttribute" ' Column 2
Cells(r, 3) = "Date/Time" ' Column 3
Cells(r, 4) = "FileSize" ' Column 4
Cells(r, 5) = "ColumnsCount" ' Column 5
On Error Resume Next
' Insert file name and get first file
f = Dir(Directory, vbReadOnly + vbHidden + vbSystem)
Do While f <> ""
r = r + 1
Cells(r, 1) = f
On Error Resume Next
' Insert file attribute
Cells(r, 2) = GetAttr(Directory & f)
On Error Resume Next
' Insert Files Date and Times
Cells(r, 3) = FileDateTime(Directory & f)
On Error Resume Next
' Insert file lengths/sizes and adjust for filesize > 2 gigabytes
FileSize = FileLen(Directory & f)
If FileSize < 0 Then FileSize = FileSize + 4294967296#
Cells(r, 4) = FileSize
On Error Resume Next
' Get next file
f = Dir
' Insert count of columns in text tab delimted files
' Cells(r, 5) = How do I write a VBA code/formula to count the total number of populated columns in "closed" text tab delimted file?
Loop
End Sub
Last edited by a moderator: