PDA

View Full Version : Solved: Delete range based on 3 cell values?



Blackie50
09-08-2010, 03:47 AM
HI

Just struggling with correct code for the following

If cells B20, B23 & B27 are empty then delete rows 12 to 29

If Range("B20").Value = "" And Range("B23").Value = "" And Range("B27").Value = "" Then
Rows("12:29").Select
Selection.Delete shift:=xlUp
End If

Tries several ways but it seems to skip over the condition - probably got it wrong

Any help appreciated

thanks

Blackie50
09-08-2010, 07:00 AM
Sub deleteifnothingUK()
Dim x As Integer, y As Integer, z As Integer, A As Integer
x = 0: y = 0: z = 0: A = 0

If (Range("B20").Value = " ") Then x = 1
If (Range("B23").Value = " ") Then y = 1
If (Range("B26").Value = " ") Then z = 1

If x = 1 Then A = A + 1
If y = 1 Then A = A + 1
If z = 1 Then A = A + 1

If A = 3 Then

Rows("12:29").Select
Selection.Delete shift:=xlUp

End If

End Sub

seems to work