Hello all:
I have a VBA code that inserts a blank row after a date condition is met. What i would like to do next, is set the newly inserted blank row and the last row as my new range.
Could anyone help me out with this?
Thank you in advance.
Hello all:
I have a VBA code that inserts a blank row after a date condition is met. What i would like to do next, is set the newly inserted blank row and the last row as my new range.
Could anyone help me out with this?
Thank you in advance.
code & sample file please
code and sample file please
Sub atest() Dim LR As Long, i As Long
Dim R As Long
LR = Range("C" & Rows.Count).End(xlUp).Row For i = 10 To LR
If Range("C" & i).Value > ([A7] + 31) Then
Rows(i).Resize(1).Insert
Exit For
End If
Next i
Display More
-- I would then like to run the code below from the last row to the newly inserted row from above--
I couldn't quite figure out what u were trying to do but im assuming 1st code only adds 1 row, second code works after the blank row & puts 2 rows between diff years? have a look
Sub test()
Dim LR As Long
Dim i As Long
Dim R As Long
Dim x As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 9 To LR
If Range("C" & i).Value > ([A7] + 31) Then
Rows(i).Resize(1).Insert
Exit For
End If
Next i
LR = Range("C" & Rows.Count).End(xlUp).Row
x = 0
For R = i + 1 To LR
If Year(Cells(R, 3)) <> Year(Cells(R + 1, 3)) Then x = x + 2
Next R
LR = LR + (x - 2)
For R = i + 1 To LR
If Year(Cells(R, 3)) <> Year(Cells(R + 1, 3).Value) Then
Rows(R + 1).Resize(2).Insert
R = R + 3
End If
Next R
End Sub
Display More
Don’t have an account yet? Register yourself now and be a part of our community!