VBA_Cancer
New Member
- Joined
- Nov 6, 2017
- Messages
- 17
Code:
Sub Searching()
Dim FilePath As String
Dim strFilename As String: strFilename = "C:\Users\Jack\Desktop\test.txt"
Dim strTextLine As String
Dim iFile As Integer: iFile = FreeFile
Dim income_a(10) As Integer, i As Integer
i = 0
Open strFilename For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=iFile]#iFile[/URL]
Do Until EOF(1)
Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , strTextLine
If Split(strTextLine, ",")(0) = searchtxt.Value Then
If IsNumeric(Split(strTextLine, ",")(1)) Then
income_a(i) = CInt(Split(strTextLine, ",")(1))
i = i + 1
End If
End If
Loop
allp.Value = WorksheetFunction.Sum(income_a)
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=iFile]#iFile[/URL]
The complete file that is being open is this:
Code:
ABC123,30000,25,15
ABC123,50000,x,...
ABC123,45000,22,32
ABC123,...,23,14
I been trying to fetch all of the integers in the 2nd position of each line and store them in an array. This keeps giving me an overflow error and I don't know why!