使用VBA在表中的特定值上方插入一行

时间:2015-08-21 13:29:20

标签: excel vba excel-vba

我的表格组织如下:

get-childitem -Exclude *.txt

我试图编写一个VBA脚本,以便在" 1"的值的每个实例上方的工作表中插入一行。在第三栏。这是我到目前为止所写的内容:

   Open Date    MaturityDate    ZeroRate
    5-May-15    5-May-15    0.006999933
    5-May-15    6-May-15    0.0069999329
    5-May-15    5-Jun-15    1
    5-May-15    6-Jul-15    0.008993128
    5-May-15    5-Aug-15    0.006744264
    5-May-15    5-Nov-15    0.006912941
    5-May-15    5-May-16    0.007104633
    5-May-15    5-May-17    0.006910929
    5-May-15    6-Nov-17    0.007017292
    5-May-15    7-May-18    0.00712202
    5-May-15    5-Nov-18    1
    5-May-15    6-May-19    0.008551509
    5-May-15    5-Nov-19    0.009734602
    5-May-15    5-May-20    0.010916848
    5-May-15    5-Nov-20    0.011779622
    5-May-15    5-May-21    0.012632521
    5-May-15    5-Nov-21    1
    5-May-15    5-May-22    0.014366506
    5-May-15    7-Nov-22    0.014935518
    5-May-15    5-May-23    0.0154865

但它似乎没有任何效果。我做错了什么?

1 个答案:

答案 0 :(得分:3)

你编码正确,但只有一个错误。您应该在行中输入 3 而不是 1

If Cells(i, 1).Value = "1" Then  

更改 3 ,例如:

If Cells(i, 3).Value = "1" Then