• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Delete row if issue

Hello all

I have a issue with this code.

When i run that macro on the sheet "Output" it work but if i run it from the sheet ("Import"), it does not delete the rows.

Do you know why?

Thanks for your help


'Delete scrap
    Dim z, LastRow1
    With Sheets("Output")
LastRow1 = Sheets("Output").Range("A" & Rows.Count).End(xlUp).Row
For z = LastRow1 To 11 Step -1
If Cells(z, "B").Value = "Total:" Or Cells(z, "E").Value = "From Da" Or Cells(z, "F").Value = "Direct" Or Cells(z, "G").Value = "All Shift" Or Cells(z, "A").Value = "OperID" Then
Cells(z, "A").EntireRow.Delete
End If
Next
End With

Open in new window

0
Wilder1626
Asked:
Wilder1626
  • 3
  • 2
1 Solution
 
Saqib Husain, SyedEngineerCommented:
Try

Sheets("Output").Cells(z, "A").EntireRow.Delete
0
 
Rory ArchibaldCommented:
You haven't qualified any of your Cells calls:
'Delete scrap
    Dim z, LastRow1
    With Sheets("Output")
LastRow1 = .Range("A" & .Rows.Count).End(xlUp).Row
For z = LastRow1 To 11 Step -1
If .Cells(z, "B").Value = "Total:" Or .Cells(z, "E").Value = "From Da" Or .Cells(z, "F").Value = "Direct" Or .Cells(z, "G").Value = "All Shift" Or .Cells(z, "A").Value = "OperID" Then
.Cells(z, "A").EntireRow.Delete
End If
Next
End With

Open in new window


Note the periods before the .Cells calls
0
 
Wilder1626Author Commented:
Oh thanks,

That easy!!!!!!!

loll
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Rory ArchibaldCommented:
You realise that your code is deleting from one sheet but may be checking cells on another if you do that?
0
 
Saqib Husain, SyedEngineerCommented:
Rory is right. You need to define where each of those cell calls are referring to. It may work well in your present scenario but you may run into trouble in some other scenario.
0
 
Rory ArchibaldCommented:
It will only work properly if the Output sheet is active, which was the original problem. ;)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now