ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] VBA TXT ¨Ì·Ó¬q¸¨¶}±Ò»Ý¨D

[µo°Ý] VBA TXT ¨Ì·Ó¬q¸¨¶}±Ò»Ý¨D

­ìTXT¶}±Ò«á¥u¯à¨Ì·ÓÀɮפºTXTÀɤ@¦¸¶}±Ò¡A¦p²Ä3¦C©Ò²£¥Íªºµ²ªG
¥Ø«e»Ý¨D¡G&¡B%¡B$ ¬°¦U¤@­Ó¬q¸¨¡A¬q¸¨®æ¼Æ¬°©T©wªº¡AÀɮ׶}±Ò«á¨Ì·Ó­Ó¬q¸¨ªº¯S§O²Å¸¹¥h¤ÀÃþ¡A¦p²Ä4¦C©Ò²£¥Íªºµ²ªG


½Ð¦U¦ì°ª¤âÀ°¦£¡A«ô°U

VBA TXT ¨Ì·Ó¬q¸¨¶}±Ò»Ý¨D.rar (19.33 KB)

Sub TEST()
Dim xPath$, xF$, xS As Worksheet, xEnd As Range, xR As Range, TT, T, N$, C%
xPath = ThisWorkbook.Path & "\"
Set xS = ThisWorkbook.Sheets("¤u§@ªí1")
Do
¡@If xF = "" Then xF = Dir(xPath & "*.txt") Else xF = Dir
¡@If xF = "" Then Exit Do
¡@If Not xS.[A:A].Find(xF, LookAT:=xlWhole) Is Nothing Then GoTo 101
¡@Set xEnd = xS.Cells(Rows.Count, 1).End(xlUp)(2)
¡@If xEnd.Row < 3 Then Set xEnd = xS.[A3]
¡@xEnd = xF
¡@
¡@Open xPath & xF For Input Access Read As #1
¡@Do Until EOF(1)
¡@¡@Line Input #1, T
¡@¡@N = Switch(T = "&", "B", T = "%", "M", T = "$", "AC", T = T, "")
¡@¡@'¡ÄT="&"¡A¨ú¢ÐÄæ¡AÃþ±À¡ã¡ã¡F§ä¤£¨ì"&%$"¡AN¬°ªÅ­È¡@
¡@¡@If N <> "" Then Set xR = xEnd(1, N): ¡@C = 0
¡@¡@'¡Ä§ä¨ì"&%$"«á¡A¥HxR©w¦ì¬°¦U¤ÀÃþªº­º®æ
¡@¡@For Each TT In Split(T, " ")
¡@¡@¡@¡@C = C + 1: ¡@xR(1, C) = TT
¡@¡@Next
¡@Loop
¡@Close #1
101: Loop
End Sub
¡@
¡@
¤j­P¦p¤W¡A¨ä¥L²Ó¸`½Ð¦Û¦æ§ó§ï©Î½Õ¾ã¡ã¡ã

TOP

¥»©«³Ì«á¥Ñ ­ã´£³¡ªL ©ó 2015-10-28 11:25 ½s¿è

N = Switch(T = "&", "B", T = "%", "M", T = "$", "AC", T = T, "")
¤]¥i¥Î¡G
N = Array("", "", "B", "M", "AC")(InStr("_&%$", T))
¡ÄInStr ­È¥u¦³0,1,2,3,4 ¤­ºØµ²ªG¡@

"_&%$"¡@«e­±¥["_"¡A¬O¬°¨¾¤îT¬OªÅ®æ®Éªº»~§P¡]»PFIND¨ç¼Æ¤@¼Ë¡Aµ²ªG¬°¢°¡^
¥i´ú¸Õ¡@MsgBox InStr("&%$", "")

Array «e­±¨â­ÓªÅ¦r²Å¡A§Y¬O¦bT¬°ªÅ­È¡]InStr­È¬°¢°¡^©Î§ä¤£¨ì¤å¦r®É¡]InStr­È¬°¢¯¡^¡A¥HªÅ¦r²ÅÅã¥Ü

TOP

¦^´_ 3# ­ã´£³¡ªL

·PÁ ­ã¤j ªGµM¼F®`
¦ý½Ð°Ý
If Not xS.[A:A].Find(xF, LookAT:=xlWhole) Is Nothing Then GoTo 101
¡@Set xEnd = xS.Cells(Rows.Count, 1).End(xlUp)(2)
¡@If xEnd.Row < 3 Then Set xEnd = xS.[A3]
¡@xEnd = xF
- - - - - -
For Each TT In Split(T, " ")
¡@¡@¡@¡@C = C + 1: ¡@xR(1, C) = TT
¡@¡@Next
­Ó§O¬O¤°»ò·N«ä¡H ¨Ï¥Î»¡©ú¬Ý¤£¤ÓÀ´
¯à½Ð­ã¤j¬°¤p§Ìµy·L¸ÑÄÀ¤@¤U¶Ü ÁÂÁÂ

TOP

¦^´_ 4# Jason80Lo

If Not xS.[A:A].Find(xF, LookAT:=xlWhole) Is Nothing Then GoTo 101
¡Ä¦pªG¤å¦rÀɦWºÙ¤w¦s¦b¡A²¤¹L¡@

Set xEnd = xS.Cells(Rows.Count, 1).End(xlUp)(2)
¡Ä¨ú±o·Ç³Æ¶ñ¤J¸ê®Æªº¦ì¸m¡]³Ì«á¤@µ§¸ê®Æªº¤U¤@®æªÅ¥Õ®æ¡^¡@

If xEnd.Row < 3 Then Set xEnd = xS.[A3]
¡Ä¦pªG³oªÅ¥Õ®æ¦C¸¹¤p¤_¢²¡A«h¨ú¢Ï¢²¡]¨¾¤î¼ÐÃDµL¤å¦rªº¿ù»~¡^¡@

xEnd = xF
¡Ä²Ä¤@®æ¶ñ¤å¦rÀɦW¡@

For Each TT In Split(T, " ")
¡@¡@C = C + 1: ¡@xR(1, C) = TT
Next
¡Ä¥HªÅ¥Õ®æ­åªR¤å¦r¡A¦A¦V¥k³v¤@¶ñ¤J¡@

TOP

¦^´_ 5# ­ã´£³¡ªL


    Á­ã¤j ²³æ¤S©úÁA ·P®¦
   ¤p§Ì¬ã¨s¤@¤U

TOP

½Ð°Ý¦pªG txtÀɤ¤ &, #, %, @ ¬Ò¬°¸ê®Æªº¤@­Ó¶}ÀY
¨ä¤¤#, % ¶}ÀY¸Ìªº¸ê®Æ¬°µL­­­Ó(¦Ó¥B¦³®É­Ô¦³¦³®É­Ô¨S¦³),
³o¼Ëªº¸Ü­n¦p¦ó¥h°Ï¤À¬q¸¨©O¡H
¦pªþ¥óÀÉ®× 2, 3¦C¬°­ì¥»Åã¥Üµ²ªG
                     6, 7¦C¬°§Æ±æªºµ²ªG
½Ð¤j¤j¨ó§UÀ°¦£

VBA TXT ¨Ì·Ó¬q¸¨¶}±Ò»Ý¨D.rar (24.3 KB)

TOP

¦^´_ 7# Jason80Lo


Do Until EOF(1)
¡@¡@Line Input #1, T
¡@¡@If T = "&" Then Set xR = xEnd(1, "B"): C = 0
¡@¡@If (T = "#" Or T = "$") And N = "" Then Set xR = xEnd(1, "M"): C = 0: N = "Y"
¡@¡@If T = "@" Then Set xR = xEnd(1, "AO"): C = 0
¡@¡@For Each TT In Split(T, " ")
¡@¡@¡@¡@C = C + 1:   xR(1, C) = TT
¡@¡@Next
Loop

TOP

¦^´_ 8# ­ã´£³¡ªL


    ÁÂÁ ­ã¤j ¤p§Ì ¬ã¨s¬ã¨s

TOP

¥»©«³Ì«á¥Ñ Jason80Lo ©ó 2015-11-8 18:30 ½s¿è

¦^´_ 8# ­ã´£³¡ªL


¡@¡@If (T = "#" Or T = "$") And N = "" Then Set xR = xEnd(1, "M"): C = 0: N = "Y"
­ã¤j½Ð°Ý³o¦æªº·N«ä¡AxEnd(1, "M")¸Ì­±ªº1¤°»ò·N«ä¡H
¤p§Ì¸Õ¥t¤T­ÓTXTÀÉ¡A¦P®É¶}±Ò«á¥u¦³²Ä¤@­Ó¯à°÷¶¶§Q¨Ì·ÓÀx¦s®æ½s±Æ(¦p¤U¹Ï)
If (T = "#" Or T = "%") And N = "" Then Set xR = xEnd(1, "FZ"): C = 0: N = "Y"

123.png

TOP

        ÀR«ä¦Û¦b : ¤f»¡¦n¸Ü¡B¤ß·Q¦n·N¡B¨­¦æ¦n¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD