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

[µo°Ý] ·Q½Ð±Ð¦p¦ó±q¤@­ÓtxtÀÉÂà¥X¦¨«Ü¦h­ÓexcelÀÉ

¥»©«³Ì«á¥Ñ luhpro ©ó 2015-2-25 22:24 ½s¿è
¦U¦ì¿Ë·Rªº¤j¤j¤È¦w
    ¦³­Ó¤p°ÝÃD·Q­n¸ò¦U¦ì½Ð¯q¡A
    ­n¦p¦ó±N¤@­Ó¦³¦n´X¦æ¸ê®ÆªºtxtÀÉ¡A¶×¥X¦¨¨C¤@¦æ ...
flowrew µoªí©ó 2015-2-25 13:58

¶È´N§A´£¨Ñªº¹ÏÀɲq´ú¤å¦rÀɪº¤º®e,¸Õ¸Õ¬Ý...
  1. Sub nn()
  2.   Dim iMode%, iBgn%, iCol%
  3.   Dim lRow&
  4.   Dim sStr$, sTemp$
  5.   Dim vD
  6.   Dim vFs, vF
  7.   
  8.   Cells.Clear
  9.   
  10.   Set vD = CreateObject("Scripting.Dictionary")
  11.   lRow = 3
  12.   iCol = 3
  13.   iMode = 0
  14.   Set vFs = CreateObject("Scripting.FileSystemObject")
  15.   Set vF = vFs.OpenTextFile(ThisWorkbook.Path & "\123.txt", 1, -2)
  16.     Do While Not vF.AtEndOfStream
  17.       sStr = Trim(vF.ReadLine)
  18.       If sStr <> "" Then
  19.       
  20.         Select Case iMode
  21.           Case Is > 2 ' ¸ê®Æ°Ï
  22.             iBgn = InStr(1, sStr, " ")
  23.             Cells(vD("1"), iCol) = Left(sStr, iBgn - 1)
  24.             
  25.             iBgn = InStr(iBgn, sStr, " ")
  26.             GoSub SkipSpace
  27.             Cells(vD("2"), iCol) = sTemp
  28.             
  29.             iBgn = InStr(iBgn, sStr, " ")
  30.             GoSub SkipSpace
  31.             Cells(vD("3"), iCol) = sTemp
  32.             
  33.             iBgn = InStr(iBgn, sStr, " ")
  34.             GoSub SkipSpace
  35.             Cells(vD("3") + 1, iCol) = sTemp
  36.             
  37.             iBgn = InStr(iBgn, sStr, " ")
  38.             GoSub SkipSpace
  39.             Cells(vD("4"), iCol) = sTemp
  40.             iCol = iCol + 1
  41.                            
  42.           Case 0 ' SN
  43.             If InStr(1, sStr, "SN") > 0 Then
  44.               Cells(lRow, 2) = "SN"
  45.               Cells(lRow, 3) = Trim(Mid(sStr, InStr(1, sStr, ":") + 1, 10))
  46.               iMode = iMode + 1
  47.               lRow = lRow + 1
  48.             End If
  49.         
  50.           Case 1 ' Model
  51.             If InStr(1, sStr, "Model") > 0 Then
  52.               Cells(lRow, 2) = "Model"
  53.               Cells(lRow, 3) = Trim(Mid(sStr, InStr(1, sStr, ":") + 1, 10))
  54.               iMode = iMode + 1
  55.               lRow = lRow + 2
  56.             End If

  57.           Case 2 ' A B C D
  58.             iBgn = InStr(1, sStr, " ")
  59.             Cells(lRow, 2) = Left(sStr, iBgn - 1)
  60.             vD("1") = lRow
  61.             
  62.             GoSub SkipSpace
  63.             lRow = lRow + 1
  64.             Cells(lRow, 2) = sTemp
  65.             vD("2") = lRow
  66.             iBgn = InStr(iBgn, sStr, " ")
  67.             
  68.             GoSub SkipSpace
  69.             lRow = lRow + 2
  70.             Cells(lRow, 2) = sTemp
  71.             vD("3") = lRow
  72.             iBgn = InStr(iBgn, sStr, " ")
  73.             
  74.             GoSub SkipSpace
  75.             lRow = lRow + 2
  76.             Cells(lRow, 2) = sTemp
  77.             vD("4") = lRow
  78.             iMode = iMode + 1
  79.         End Select
  80.       End If
  81.     Loop
  82.   vF.Close
  83.   
  84. Exit Sub

  85. SkipSpace:
  86.     Do While Mid(sStr, iBgn, 1) = " "
  87.       iBgn = iBgn + 1
  88.     Loop
  89.     sTemp = Trim(Mid(sStr, iBgn, IIf(InStr(iBgn, sStr, " ") = 0, _
  90.                            Len(sStr) + 1, InStr(iBgn, sStr, " ")) - iBgn))
  91.   Return
  92. End Sub
½Æ»s¥N½X
test.zip (10.16 KB)

TOP

        ÀR«ä¦Û¦b : ¨Ã«D¦³¿ú¾{¬O§Ö¼Ö¡A°Ý¤ßµL·\¤ß³Ì¦w¡C
ªð¦^¦Cªí ¤W¤@¥DÃD