Skip condition if cell is blank

K

Kash

I have 4 conditions

1) If Sheets("Details").Range("H" & lngRow) > Date - 90 And _
2) Sheets("Details").Range("F" & lngRow) = Sheets("Search").Range("C2") And _
3) Sheets("Details").Range("J" & lngRow) = Sheets("Search").Range("C4") And _
4) Sheets("Details").Range("I" & lngRow) = Sheets("Search").Range("E4") Then

if Sheets("Search").Range("E2") is blank then condition 1 should be skipped
if Sheets("Search").Range("C2") is blank then condition 2 should be skipped
if Sheets("Search").Range("C4") is blank then condition 3 should be skipped
if Sheets("Search").Range("E4") is blank then condition 4 should be skipped

Please help me with this..

--------------------------------------

Sub GetAll()
Dim lngRow As Long
Dim lngLastRow As Long
Dim lngNewRow As Long
Dim varTemp As Variant

Sheets("Search").Select
Range("A9:L65536").Select
Selection.ClearContents
Application.Goto Reference:="R9C1"

Application.ScreenUpdating = False
lngLastRow = Sheets("Details").Cells(Rows.Count, "B").End(xlUp).Row
lngNewRow = Sheets("Search").Cells(Rows.Count, "A").End(xlUp).Row + 1
For lngRow = 1 To lngLastRow

If Sheets("Details").Range("H" & lngRow) > Date - 90 And _
Sheets("Details").Range("F" & lngRow) = Sheets("Search").Range("C2") And _
Sheets("Details").Range("J" & lngRow) = Sheets("Search").Range("C4") And _
Sheets("Details").Range("I" & lngRow) = Sheets("Search").Range("E4") Then

varTemp = Sheets("Details").Range(lngRow & ":" & lngRow)
Sheets(4).Range(lngNewRow & ":" & lngNewRow) = varTemp
lngNewRow = lngNewRow + 1
End If
Next
 
B

Bernard Liengme

Not sure I totally understand question but:
Untested but this is what I would try to 'skip' the first test
If (Sheets("Details").Range("H" & lngRow) > Date - 90 or
Sheets("Search").Range("E2") ="") And _
Sheets("Details").Range("F" & lngRow) = Sheets("Search").Range("C2") And _
Sheets("Details").Range("J" & lngRow) = Sheets("Search").Range("C4") And _
Sheets("Details").Range("I" & lngRow) = Sheets("Search").Range("E4")

If this works for you then extend the method to the other tests.
best wishes
 
K

Kash

I actually need to skip only that particular statement if a particular cell
is blank.. other statements shouls execute..

if Sheets("Search").Range("E2") is blank then condition 1 should be skipped
if Sheets("Search").Range("C2") is blank then condition 2 should be skipped
if Sheets("Search").Range("C4") is blank then condition 3 should be skipped
if Sheets("Search").Range("E4") is blank then condition 4 should be skipped
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top