Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 是否使用VBA在文本文件中查找多次出现的字符串?_Excel_Vba - Fatal编程技术网

Excel 是否使用VBA在文本文件中查找多次出现的字符串?

Excel 是否使用VBA在文本文件中查找多次出现的字符串?,excel,vba,Excel,Vba,我有一个大的文本文件,其中包含文本uu_uz_u1_u:u,后跟以下数据: _ _Z_1_:_0_1_3_4_2 Fixed Totaliser Period 1 Reset Report NET sales 57 £202.05 CASH in Drawer 55 £172.35 CREDIT in Drawer 2 £29.70 TOT

我有一个大的文本文件,其中包含文本uu_uz_u1_u:u,后跟以下数据:

_ _Z_1_:_0_1_3_4_2 Fixed Totaliser Period 1 Reset Report NET sales 57 £202.05 CASH in Drawer 55 £172.35 CREDIT in Drawer 2 £29.70 TOTAL in Drawer 57 £202.05 每个文件中有两个u_Z_1_u:u文本。 我试图让宏找到u_uz_u1:u,然后在上述情况下提高现金金额172.35英镑和信用等

我尝试使用一个代码来指定文本文件,然后使用InStr函数,但它只会识别第一次出现。感谢您的帮助。

您将返回第一次出现的位置。使用该位置开始搜索第二个

dim bffr as string, p as long
bffr = (◄ assign the text here)
p = instr(p + 1, bffr, "_ _Z_1_:_", vbtextconpare)
do while cbool(p)

  '_ _Z_1_:_ was found; process it based upon the starting position p

  'see if there are other occurrences of _ _Z_1_:_
  p = instr(p + 1, bffr, "_ _Z_1_:_", vbtextconpare)
loop

通过在找到的最后一个位置之前开始一个字符,不断推进搜索,您将在保存文本的缓冲区中穿行,并为每个匹配项拾取一个新的p。当再也找不到时,InStr会将0返回到p。

张贴您尝试过的代码。编辑您的问题,不要将其添加到评论中。