Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
12
返回列表 发新帖
楼主: studystudy

[已解决]求助:关于 间隔提取文本。

[复制链接]
 楼主| 发表于 2011-10-2 09:36 | 显示全部楼层
。。谢谢

版主老师  国庆快乐。{:011:}
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

发表于 2011-10-3 22:52 | 显示全部楼层
本帖最后由 fjmxwrs 于 2011-10-3 22:59 编辑

回复 studystudy 的帖子

  1. Sub Tqss()
  2. Dim arr(), x&, i&, j&, len_arr&
  3. Dim LineString As String
  4. Dim iFileNumber As Integer 'File number
  5. Dim openFileName, inputFileName As String
  6. iFileNumber = FreeFile '获得一个没有被使用过的文件编号
  7. openFileName = ThisWorkbook.Path & "\test.txt"
  8. Open openFileName For Input As #iFileNumber '打开文本文件
  9. len_arr = 1
  10. Do While Not EOF(1) '只要没有到文件末尾,就在文本文件内循环
  11. Line Input #1, LineString '读取文本文件一行数据
  12. LineString = Replace(LineString, " ", "") '用replace函数把" "处理掉
  13. ReDim Preserve arr(1 To (len_arr))
  14. arr(len_arr) = LineString
  15. len_arr = len_arr + 1
  16. Loop
  17. Close #iFileNumber '关闭文件
  18. inputFileName = ThisWorkbook.Path & "\result.txt"
  19. Open inputFileName For Output As #iFileNumber '创建新的文件或者覆盖已经存在的文件
  20. With Sheet1
  21. i = [a1] + 1
  22. j = [b1]
  23. For x = UBound(arr) To 1 Step -i
  24. j1 = j1 + 1
  25. If j1 <= j Then
  26. Print #iFileNumber, arr(x)
  27. End If
  28. Next x
  29. End With
  30. Close #iFileNumber '关闭文件
  31. End Sub
复制代码



help_1001.zip (11.93 KB, 下载次数: 2)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-30 05:35 , Processed in 0.300298 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表