Help with Visual Basic for Excel
Hi Kelli,
Thanks Norman! I tried it, but it deletes ALL the rows, even if P is
null.
Your request was to delete all rows where column P is populated:
I need help with code to delete all rows for which column P is not empty
That is what the suggested code does. The line:
If Not IsEmpty(rCell) Then
ensures that rows will not be deleted if the corresponding column P cell is
empty.
If, therefore, this is not your experience, it would seem likely that the
'null' cells are not, in fact, empty; perhaps these cells contain a formula
which returns an empty string, or perhaps the cells appear empty but contain
an apostrophe.
I would suggest, therefore, that you check the 'null' cells to verify their
contents.
If you still experience problems, post back with additional information
about the contentious column P cells.
---
Regards,
Norman
"KellyInCali" wrote in message
...
Thanks Norman! I tried it, but it deletes ALL the rows, even if P is
null.
-Kelly
"Norman Jones" wrote:
Hi Kelly,
Try:
'================
Public Sub Tester()
Dim rng As Range
Dim rCell As Range
Dim delRng As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim CalcMode As Long
Set WB = ActiveWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE
Set rng = Intersect(SH.UsedRange, SH.Columns("P:P"))
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
For Each rCell In rng.Cells
If Not IsEmpty(rCell) Then
If delRng Is Nothing Then
Set delRng = rCell
Else
Set delRng = Union(rCell, delRng)
End If
End If
Next rCell
If Not delRng Is Nothing Then
delRng.EntireRow.Delete
End If
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'<<================
---
Regards,
Norman
"KellyInCali" wrote in message
...
I need help with code to delete all rows for which column P is not
empty.
Thanks in advance.. Kelli
|