how to write an if/then block #2

J

Janis

I tried putting "ands" in between the lines to connect them between the if
and end if.
The compiler stops on the delete line.
I need all three statements to work if there is a date on the first line.
Else exit sub.
thanks,

Sub deleteDateRow1()
Dim FrReptDate As Date
Dim ToReptDate As Date
Dim Rng As Range
Rng = Range("A1")
If Rng.Value.Date Then FrReptDate = Rng.Value And ToReptDate = Rng.Offset(0,
1).Value
and Rng.EntireRow.Delete Shift:=xlUp

Debug.Print FrReptDate, ToReptDate
End If
Exit Sub
End Sub
 
J

JE McGimpsey

Janis said:
I tried putting "ands" in between the lines to connect them between the if
and end if.

You can't make up your own syntax - And is a logical operator which
evaluates the left and right arguments for their boolean (True/False or
non-zero/zero) values and returns True or False. It doesn't "connect"
lines.
The compiler stops on the delete line.

Yup - Rng.EntireRow.Delete doesn't return a boolean value so using And
wouldn't work.
I need all three statements to work if there is a date on the first line.
Else exit sub.

See my answer in your other thread.
 

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