ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   long if statement (https://www.excelbanter.com/excel-programming/308012-long-if-statement.html)

LiSa

long if statement
 
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




Trevor Shuttleworth

long if statement
 
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
"LiSa" wrote in message
...
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







All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com