jalrs
Active Member
- Joined
- Apr 6, 2022
- Messages
- 300
- Office Version
- 365
- Platform
- Windows
Hello guys,
I suspect it is a double if clause related issue, but as stated on the title, I need to click twice on my macro assigned button to make it run until the end.
First click it deletes the rows according first if clause
Second click it adds rows according to second if clause.
Code as follows and I can share sample of data with you, if needed.
Any help is greatly appreciated.
Thanks
I suspect it is a double if clause related issue, but as stated on the title, I need to click twice on my macro assigned button to make it run until the end.
First click it deletes the rows according first if clause
Second click it adds rows according to second if clause.
Code as follows and I can share sample of data with you, if needed.
VBA Code:
Sub play2()
Dim livro1 As Workbook
Dim folha1 As Worksheet
Dim folha2 As Worksheet
Dim ultimalinha1 As Long, ultimalinha2 As Long, ultimalinha3 As Long, i As Long
Set livro1 = ThisWorkbook
Set folha1 = livro1.Worksheets("ZPO1")
Set folha2 = livro1.Worksheets("Play")
ultimalinha1 = folha1.Cells(Rows.Count, "A").End(xlUp).Row
ultimalinha2 = folha2.Cells(Rows.Count, "M").End(xlUp).Row
ultimalinha3 = folha2.Cells(Rows.Count, "L").End(xlUp).Row
folha2.UsedRange.Offset(1).Cells.ClearContents
With folha1
.Range("A2:O" & ultimalinha1).Copy
folha2.Cells(2, 1).PasteSpecial Paste:=xlPasteFormats
folha2.Cells(2, 1).PasteSpecial Paste:=xlPasteValues
End With
For i = ultimalinha2 To 2 Step -1
If folha2.Cells(i, "M") = "0" Then
folha2.Rows(i).Delete
End If
Next i
For i = ultimalinha3 To 2 Step -1
If folha2.Cells(i, "L").Value > folha2.Cells(i, "M").Value Then
folha2.Rows(i).Insert
End If
Next i
Application.CutCopyMode = False
folha2.Activate
folha2.Range("A2").Select
End Sub
Any help is greatly appreciated.
Thanks