Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Vba to delete entire row

Posted on 2016-11-14
6
Medium Priority
?
172 Views
Last Modified: 2016-11-15
Can an expert provide me with VBA code that will delete the entire row if it finds the number 1 in column ‘O’ [must be a singular 1 not 21, 31 etc]

Many thanks in advance
0
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 34

Expert Comment

by:Norie
ID: 41887468
Try this.

Dim I As Long

    For I = Range("O" & Rows.Count).End(xlUp).Row Step -1
        If Cells(I, "O").Value = 1 Then
            Rows(I).EntireRow.Delete
        End If
    Next I

Open in new window

0
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 1000 total points
ID: 41887474
Here
Sub Demo()
    Dim lngLastRow As Long
    Dim lngCurrentRow As Long

    With ActiveSheet
        lngLastRow = Range("O" & Rows.Count).End(xlUp).Row
        For lngCurrentRow = lngLastRow To 1 Step -1
            With .Cells(lngCurrentRow, "O")
                If Not IsError(.Value) Then
                    If .Value = "1" Then .EntireRow.Delete
                End If
            End With
        Next lngCurrentRow
    End With
End Sub

Open in new window

0
 

Author Comment

by:Jagwarman
ID: 41887478
Hi Norie

this row gives me a syntax error

For I = Range("O" & Rows.Count).End(xlUp).Row Step -1
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 34

Accepted Solution

by:
Norie earned 1000 total points
ID: 41887481
Too early in the morning.:)

This is how it should read.
Dim I As Long

    For I = Range("O" & Rows.Count).End(xlUp).Row To 1 Step -1
        If Cells(I, "O").Value = 1 Then
            Rows(I).EntireRow.Delete
        End If
    Next I

Open in new window

0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41887488
HI,

pls try
Sub Macro1()
'
' Macro1 Macro
'
   Set c = Range("O" & Rows.Count)
   For lCol = 1 To WorksheetFunction.CountIf(Range("O:O"), 1)
        Set c = Range("O:O").Find(What:="1", LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False)
            c.EntireRow.Delete
   Next lCol
 
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:Jagwarman
ID: 41887494
Many thanks both really good but EE forces me to make one Best.

Regards
Jagwarman
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question