my code is this for the above result.
Sub StatUpdate()
Dim FileName As String
Dim FileNum As Integer
Dim S As Long
Dim strline As String
Dim CurVar As String
Dim PrevVar As String
Dim intColorIndex As String
Dim intCounter6 As Integer
Dim intCounter7 As Integer
Dim intCounter8 As Integer
Dim intCounter9 As Integer
Dim intcounter10 As Integer
Dim intFreeFileNumber As Integer
intFreeFileNumber = FreeFile
intCounter6 = 0
intCounter7 = 0
intCounter8 = 0
intCounter9 = 0
intcounter10 = 0
Open "D:\TBStatYTD\sourcefile\TB-USD-EDITED.txt" For Input As #intFreeFileNumber
Do While Not EOF(intFreeFileNumber)
Line Input #intFreeFileNumber, strline
If CurVar = "" Then
CurVar = PrevVar
End If
If CurVar = "080149" Then
intCounter6 = intCounter6 + 1
If intCounter6 = 1 Then
ActiveSheet.Cells(S, 1) = "CN-AGENTS"
ActiveSheet.Cells(S, 1).Interior.ColorIndex = 35
S = S + 1
ActiveSheet.Cells(S, 1) = CurVar
End If
Select Case Trim(Mid(strline, 22, [10]))
'START EXPORT
Case "441110", "441120", "441130", "441210", "441220", "441230", "441330"
ActiveSheet.Cells(S, 2) = Mid(strline, 22, 10)
ActiveSheet.Cells(S, 3) = Mid(strline, 45, 31)
ActiveSheet.Cells(S, 4) = Mid(strline, 76, 20)
ActiveSheet.Cells(S, 5) = Mid(strline, 95, 19)
ActiveSheet.Cells(S, 5).Interior.ColorIndex = 36
ActiveSheet.Cells(S, 6) = Right(strline, 18)
ActiveSheet.Cells(S, 6).Interior.ColorIndex = 36
S = S + 1
intCountPlus = intCountPlus + 1
'END EXPORT
'START IMPORT
Case "758141", "758142", "758143", "758153"
ActiveSheet.Cells(S, 2) = Mid(strline, 22, 10)
ActiveSheet.Cells(S, 3) = Mid(strline, 45, 31)
ActiveSheet.Cells(S, 4) = Mid(strline, 76, 20)
ActiveSheet.Cells(S, 5) = Mid(strline, 95, 19)
ActiveSheet.Cells(S, 5).Interior.ColorIndex = 40
ActiveSheet.Cells(S, 6) = Right(strline, 18)
ActiveSheet.Cells(S, 6).Interior.ColorIndex = 40
S = S + 1
'END IMPORT
End Select
End If
If CurVar = "080630" Then
intCounter7 = intCounter7 + 1
If intCounter7 = 1 Then
ActiveSheet.Cells(S, 1) = "PRE-CEPA"
ActiveSheet.Cells(S, 1).Interior.ColorIndex = 35
S = S + 1
ActiveSheet.Cells(S, 1) = CurVar
End If
Call AccountUpdate(strline, S)
End If
If CurVar = "080631" Then
intCounter8 = intCounter8 + 1
If intCounter8 = 1 Then
ActiveSheet.Cells(S, 1) = "CEPA-SOUTH"
ActiveSheet.Cells(S, 1).Interior.ColorIndex = 35
S = S + 1
ActiveSheet.Cells(S, 1) = CurVar
End If
Call AccountUpdate(strline, S)
End If
If CurVar = "080639" Then
intCounter9 = intCounter9 + 1
If intCounter9 = 1 Then
ActiveSheet.Cells(S, 1) = "CEPA-CENTRAL"
ActiveSheet.Cells(S, 1).Interior.ColorIndex = 35
S = S + 1
ActiveSheet.Cells(S, 1) = CurVar
End If
Call AccountUpdate(strline, S)
End If
If CurVar = "080640" Then
intcounter10 = intcounter10 + 1
If intcounter10 = 1 Then
ActiveSheet.Cells(S, 1) = "CEPA-NORTH"
ActiveSheet.Cells(S, 1).Interior.ColorIndex = 35
S = S + 1
ActiveSheet.Cells(S, 1) = CurVar
End If
Call AccountUpdate(strline, S)
End If
PrevVar = CurVar
Loop
Close #1
End Sub
Sub AccountUpdate(tempStrLine As String, i As Long)
Select Case Trim(Mid(tempStrLine, 22, [10]))
Case "421101", "421106", "421111", "421201", "441210", "441220", "441230", "441330"
ActiveSheet.Cells(i, 2) = Mid(tempStrLine, 22, 10)
ActiveSheet.Cells(i, 3) = Mid(tempStrLine, 45, 31)
ActiveSheet.Cells(i, 4) = Mid(tempStrLine, 76, 20)
ActiveSheet.Cells(i, 5) = Mid(tempStrLine, 95, 19)
ActiveSheet.Cells(i, 5).Interior.ColorIndex = 36
ActiveSheet.Cells(i, 6) = Right(tempStrLine, 18)
ActiveSheet.Cells(i, 6).Interior.ColorIndex = 36
i = i + 1
Case "758041", "758042", "758043", "758052", "758053"
ActiveSheet.Cells(i, 2) = Mid(tempStrLine, 22, 10)
ActiveSheet.Cells(i, 3) = Mid(tempStrLine, 45, 31)
ActiveSheet.Cells(i, 4) = Mid(tempStrLine, 76, 20)
ActiveSheet.Cells(i, 5) = Mid(tempStrLine, 95, 19)
ActiveSheet.Cells(i, 5).Interior.ColorIndex = 40
ActiveSheet.Cells(i, 6) = Right(tempStrLine, 18)
ActiveSheet.Cells(i, 6).Interior.ColorIndex = 40
i = i + 1
End Select
End Sub
I am really sorry if my code is not code for I am still learning
Actually, I haven't use the the userange.address and sumfunction in my code because I am still on the testing process.
Need your expertise and advise.