Hi guys, i need some help with a macro that is probably simple to you, but i don't even know how to explain xD
So i got helped here before with a macro that copies a value from a cell E2 into A2 , if x-y<0 or x-z<0, this every 45 rows.
When the value i want is copied in column A, i want to keep 45 rows starting from that value. For example, if i have A2 value, i want to keep all the rows from A2 to A46.
If the value in A47 is not copied, the following 44 rows (so from row 47 to 91) can be deleted.
If there is a value in A92, then keep from A92 to A136 .... i usually have like 20k rows, so as long as it takes.
How can i implement this code into the one i posted ?
Thank you for your help!
So i got helped here before with a macro that copies a value from a cell E2 into A2 , if x-y<0 or x-z<0, this every 45 rows.
VBA Code:
Option Explicit
Sub Seb1991_V2()
Dim ws As Worksheet
Set ws = Worksheets("Foglio1")
Dim LRow As Long, n As Long
LRow = WorksheetFunction.Ceiling(ws.Cells(Rows.Count, "E").End(xlUp).Row, 45)
n = LRow - 45
Dim a, b
a = ws.Range("E2:L" & LRow)
ReDim b(1 To UBound(a, 1), 1 To 1)
Dim i As Long
For i = 1 To LRow - 45 Step 45
Debug.Print a(i + 5, 8)
Debug.Print a(i + 20, 8)
Debug.Print a(i + 31, 8)
If a(i, 1) <> "" And (a(i + 5, 8) - a(i + 20, 8) < 0 Or a(i + 5, 8) - a(i + 31, 8) < 0) Then b(i, 1) = a(i, 1)
Next i
ws.Range("A2").Resize(UBound(b, 1)).Value = b
End Sub
When the value i want is copied in column A, i want to keep 45 rows starting from that value. For example, if i have A2 value, i want to keep all the rows from A2 to A46.
If the value in A47 is not copied, the following 44 rows (so from row 47 to 91) can be deleted.
If there is a value in A92, then keep from A92 to A136 .... i usually have like 20k rows, so as long as it takes.
How can i implement this code into the one i posted ?
Thank you for your help!
Last edited by a moderator: