Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
VBA在找到D后的第二年增加_Vba_Loops_Formula_Offset - Fatal编程技术网

VBA在找到D后的第二年增加

VBA在找到D后的第二年增加,vba,loops,formula,offset,Vba,Loops,Formula,Offset,我有j14(1月14日)到d14(C2:c13列)的数据。我希望每次运行时日期都增加1,所以从d14到j15 f15等等 活页5包含a1:12列中的J-D和b1:b12列中的14 我想从c2:c13的范围下降到每运行一次 下面是我目前拥有的,但它只适用于1月15日 Sub test() Dim SrchRng As Range, cel As Range Dim lastRow As String lastRow = ActiveSheet.Cells(Rows.Count, "C").En

我有j14(1月14日)到d14(C2:c13列)的数据。我希望每次运行时日期都增加1,所以从d14到j15 f15等等 活页5包含a1:12列中的J-D和b1:b12列中的14 我想从c2:c13的范围下降到每运行一次

下面是我目前拥有的,但它只适用于1月15日

Sub test()

Dim SrchRng As Range, cel As Range
Dim lastRow As String

lastRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row + 1

Set SrchRng = Range("C2:C13")

For Each cel In SrchRng
If InStr(1, cel.Value, "D") > 0 Then
    cel.Offset(1, 50).Value = Range("C" & lastRow).Select
ActiveCell.Formula = "=Sheet5!A1&Sheet5!B1+1"
End If
Next cel

End Sub

您的搜索范围设置为12行。我刚刚通过使用“范围(Selection.Offset(-1,0),Selection.FillDown”解决了这个问题。感谢回复您应该使用
Range(“C2:C”和lastRow
我想您的搜索范围设置为12行。我刚刚通过使用“Range(Selection.Offset(-1,0),Selection.FillDown)”解决了这个问题。感谢回复您应该使用
Range(“C2:C”和lastRow
我想