Advertisement
YasserKhalil2019

T4713_Export Each Branch To Text File

Mar 25th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. https://excel-egy.com/forum/t4713
  2. ---------------------------------
  3.  
  4. Sub Export_Each_Branch_To_Text_File()
  5. Dim sPath$, s$, txt$, i%, r&, c&
  6.  
  7. sPath = ThisWorkbook.Path & "\Output Files\"
  8. If Len(Dir(sPath, vbDirectory)) = 0 Then MkDir sPath
  9.  
  10. For c = 3 To 16
  11. txt = Empty: s = Empty
  12. For r = 4 To Cells(Rows.Count, 1).End(xlUp).Row
  13. If Trim(Cells(r, c).Value) <> "" Then
  14. s = Cells(r, 1).Value & ", " & Cells(r, c).Value
  15. txt = txt & IIf(txt = Empty, Empty, vbNewLine) & s
  16. End If
  17. Next r
  18.  
  19. If txt <> Empty Then
  20. Open sPath & Cells(3, c).Value & ".txt" For Output As #1
  21. Print #1, txt
  22. Close #1
  23. End If
  24. Next c
  25.  
  26. MsgBox "The Text Files Can Be Found In " & sPath, 64, "Complete"
  27. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement