long if statement

  • Thread starter Thread starter LiSa
  • Start date Start date
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
 
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
 

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

Back
Top