Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.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 在范围内添加条件下的行_Vba_Excel - Fatal编程技术网

Vba 在范围内添加条件下的行

Vba 在范围内添加条件下的行,vba,excel,Vba,Excel,我恳请你在这个问题上帮助我 请参阅以下资料: 名称开始日期结束日期 约翰2016年7月17日2017年7月17日 约翰2017年7月17日2018年7月17日 玛丽亚2017年8月1日2018年8月1日 克里斯2018年1月5日2019年1月5日 工人及其工作年限。我需要在工人的工作年度结束时为他/她添加新行。例如,当日期>2018年7月17日时,我需要为John添加新行。日期=今天公式 看起来很简单,但这是我假期模块的一部分 我开始写这样的代码 Sub AddWorkingYearLine()

我恳请你在这个问题上帮助我

请参阅以下资料:

名称开始日期结束日期

约翰2016年7月17日2017年7月17日

约翰2017年7月17日2018年7月17日

玛丽亚2017年8月1日2018年8月1日

克里斯2018年1月5日2019年1月5日

工人及其工作年限。我需要在工人的工作年度结束时为他/她添加新行。例如,当日期>2018年7月17日时,我需要为John添加新行。日期=今天公式

看起来很简单,但这是我假期模块的一部分

我开始写这样的代码

Sub AddWorkingYearLine()

Dim WorVac As Worksheet:                Set WorVac = Worksheets("WorkerVacation")
Dim i As Long
Dim LRow As Long
Dim LCol As Long
Dim MyTable As Variant

LRow = Range("A1048576").End(xlUp).Row: LCol = Range("XFD4").End(xlToLeft).Column

MyTable = Range(Cells(4, 1), Cells(LRow, LCol))

For i = 1 To UBound(MyTtable, 1)

If Branches.Range("C" & i) > Range("G1") Then  'Range("G1") = today formula

End If
Next i 
端接头


谢谢大家!

以下是我对你要求的解释。如果当前行的C列出现在今天之前,则它将插入一行,将当前行复制到新行中,然后在这些日期增加年份

Sub AddWorkingYearLine()

    Dim i As Long
    For i = Cells(Rows.count, "A").End(xlUp).row To 4 Step -1
        'make sure it's not an "old entry"
        If Cells(i, "A").Value2 <> Cells(i + 1, "A").Value2 Then
            'if today occurs after "end date" then
            If Date > CDate(Cells(i, "C").value) And Len(Cells(i, "C").Value2) > 0 Then
                'insert row
                Rows(i + 1).Insert Shift:=xlShiftDown

                'copy row down
                Rows(i + 1).value = Rows(i).value

                'update dates
                Cells(i + 1, "B").value = Cells(i, "C").value
                Cells(i + 1, "C").value = DateAdd("yyyy", 1, CDate(Cells(i, "C").value))
            End If
        End If
    Next i

End Sub

谢谢你的好办法。对于标准范围的数据,代码可以正常工作。但我使用表来存储数据。如何调整表格样式的代码?抱歉,还有其他问题。一切正常。非常感谢你的支持。