I am having a hard time getting the below logic to work. The issue seems to be where the Year function is placed. It seems to be skipping over the logic completely, yet i'm not sure how to encorporate the year function without breaking the with loop.
Sub BlankLine()
Dim Col_year As Variant
Dim Col_st As Variant
Dim Col_btc As Variant
Dim BlankRows As Long
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Dim ws As Worksheet
Dim wb As Workbook
Dim state_ar() As Variant
Col_year = "E"
Col_st = "C"
Col_btc = "D"
StartRow = 1
BlankRows = 1
Set wb = ThisWorkbook
Set ws = wb.Worksheets("LU_WK_BENE_AMT")
LastRow = ws.Cells(Rows.Count, Col_year).End(xlUp).Row
Application.ScreenUpdating = False
state_ar = Array("02", "03")
For Each State In state_ar
With ws
For R = LastRow To StartRow + 1 Step -1
If Year(.Cells(R, Col_year).Value) = 2020 And .Cells(R, Col_st) = i Then
.Cells(R + 1, Col_year).EntireRow.Insert Shift:=xlDown
.Cells(R + 1, Col_year).Value = 2021
.Cells(R + 1, Col_st).Value = .Cells(R, Col_st).Value
.Cells(R + 1, Col_btc).Value = .Cells(R, Col_btc).Value
End If
Next R
End With
Next
Application.ScreenUpdating = True
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…