循环插入行,然后在VBA

时间:2019-06-14 11:43:34

标签: vba excel-2010

我有一列带有已排序的“ t / n”或“ s / n”列表。我也有一个脚本,它将遍历每个单元格,检查't / n'何时切换到's / n'(t / n始终优先排序),然后插入三行空白。

问题是,在插入行之后,我想选择刚分离的(感谢新行)“ s / n”数据上方的单元格-这是因为我随后将调用另一个脚本,该脚本将提取标题列表(位于“ s / n”数据上方)

到目前为止,我有:

Sub modTestTemplate()

Dim rngTestTemplate As Range
Set rngTestTemplate = Range("B2").End(xlDown).Offset(4, 0)
rngTestTemplate.Select

Dim LastRow As Integer
Dim CurrentRow As Integer
LastRow = rngTestTemplate.End(xlDown).Row
CurrentRow = 1

Do While CurrentRow <= LastRow

    If Range("B" & CurrentRow).Value = "s/n" Then
        Range("B" & CurrentRow).EntireRow.Resize(3).Insert xlUp
        LastRow = LastRow + 1
        CurrentRow = CurrentRow + 1
        Exit Do
    End If

    CurrentRow = CurrentRow + 1 ' this sets the cell back to the start for the loop

Loop

'when the loop is done I'm wanting to select the cell just above 's/n' as the data needs headers

End Sub

1 个答案:

答案 0 :(得分:0)

capt2[1,1] capt2[2,1] capt2[3,1] capt2[4,1] capt2[5,1] capt2[6,1] capt2[1,2] capt2[2,2] capt2[3,2] capt2[4,2] 1 4.582288e-05 5.115372e-05 6.409558e-05 7.132340e-05 6.927382e-05 5.727399e-05 2.753242e-05 3.106131e-05 3.832073e-05 4.270945e-05 2 4.675470e-05 5.045181e-05 6.467788e-05 7.112534e-05 6.809241e-05 5.885455e-05 2.789134e-05 3.097479e-05 3.790915e-05 4.176663e-05 3 4.586335e-05 5.127838e-05 6.344857e-05 6.934458e-05 6.622970e-05 5.651329e-05 2.795094e-05 3.120102e-05 3.790188e-05 4.172773e-05 4 4.572750e-05 5.150407e-05 6.333068e-05 7.145439e-05 6.624694e-05 5.836059e-05 2.795106e-05 3.055858e-05 3.826570e-05 4.172327e-05 5 4.740812e-05 5.113890e-05 6.397921e-05 7.163161e-05 6.838507e-05 5.620327e-05 2.790780e-05 3.083819e-05 3.821806e-05 4.198080e-05 6 4.583460e-05 5.106634e-05 6.340507e-05 7.030548e-05 6.886533e-05 5.901374e-05 2.792663e-05 3.136544e-05 3.862876e-05 4.177590e-05 完成了工作-正如SJR指出的那样。