long if statement

L

LiSa

I'm sure there must be a short way of doing this
I only want the code to execute if all the cells in a
range are filled. So far I have this.
All the cells are on the same row


If range("A1")<>"" and range("A2")<>"" _
and range("A3")<>"" etc etc then
execute code
end if

TIA
 
T

Trevor Shuttleworth

LiSa

maybe you could use something like this:

Sub test1()
If WorksheetFunction.CountA(Range("A1:A3")) = 3 Then
MsgBox "execute code"
End If
End Sub

Instead of:

Sub test2()
If Range("A1") <> "" _
And Range("A2") <> "" _
And Range("A3") <> "" Then
MsgBox "execute code"
End If
End Sub


Regards

Trevor
 
Top