2016-05-17 35 views
-1

在Excel 2013我有这个结构的大量数据文件:复制单元格的值,直到某些条件

 
    ae:|xxxxx|yyyyy| 
    1|aaaaa|bbbbb| 
    2|ccccc|ddddd| 
... 
total|?????|!!!!!| 
    ae:|zzzzz|wwwww| 
    41|asdas|aswww| 
    42|hfghf|yuytu| 
... 
total|?????|!!!!!| 
... 

需要你帮那哪里是“?????”放置“ae:”单元之后的数据。 对于上面的例子必须是:

 
    ae:|xxxxx|yyyyy| 
    1|aaaaa|bbbbb| 
    2|ccccc|ddddd| 
... 
total|xxxxx|yyyyy| 
    ae:|zzzzz|wwwww| 
    41|asdas|aswww| 
    42|hfghf|yuytu| 
... 
total|zzzzz|wwwww| 
... 

任何帮助将apreciated。 thnx。

+0

显示您的代码。 – findwindow

回答

0

这是一个裸机VBA子程序来做到这一点。这些都是非常基本的东西,应该足以让你指出你的工作簿的正确方向。在提出跟进问题之前,请给出一个很好的尝试来根据您的需求进行修改。

Sub getTotal() 
    Dim intLastRow as integer 
    Dim intRow as integer 
    Dim strAEval1 as string 'variable to hold your first ae value 
    Dim strAEval2 as string 'variable to hold your second ae value 

    intLastRow = 5000 'change this to your last row in your spreadsheet 

    'Assuming this data is in Sheet1, Columns A, B, and C and starting at Row 1 
    ' loop through each row 
    for intRow = 1 to intLastRow 

     'if you find 'ae' then copy the values 
     If Sheet1.Range("A" & intRow).value = "ae:" Then 
      strAEval1 = Sheet1.Range("B" & intRow).value 
      straeval2 = Sheet1.Range("C" & intRow).value 

     'if you find 'total' then paste the values we copied 
     Elseif Sheet1.Range("A" & intRow).value = "total" Then 
      Sheet1.Range("B" & intRow).value = strAEval1 
      Sheet1.Range("C" & intRow).value = strAEval2 
     End if 
    Next intRow 
End Sub 
相关问题