Writing an If Statement for group of cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a group of cells in a template, on the single cell I can run the routine
If Worksheets("Inventory").Range("AG11") = "" Then
frmInventory.Hide
pswd.Protect "xxxxxx"
Exit Sub
End If
and it works great, but when I try to convert to cover several cells it
keeps on failing. The Range of Cells that I am trying to run a check on are:
B25:B47, B50:B61, B64:B66, B86:B94,B103:B112,B114:B114,B116:B118,B120:b122,
etc. I named these group of cells oClearCells. Any help would be greatly
appreciated and very welcomed.
 
Larry,
Give this a try, it assumes that you protecting the Inventory worksheet.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

Sub BBB()
With Worksheets("Inventory")
If Application.CountA(.Range("oClearCells")) = .Range("oClearCells").Count Then
frmInventory.Hide
.Protect "xxxxxx"
Exit Sub
Else
MsgBox "Got some blanks "
End If
End With
End Sub
'------------

"Larry"
<[email protected]>
wrote in message
I have a group of cells in a template, on the single cell I can run the routine
If Worksheets("Inventory").Range("AG11") = "" Then
frmInventory.Hide
pswd.Protect "xxxxxx"
Exit Sub
End If
and it works great, but when I try to convert to cover several cells it
keeps on failing. The Range of Cells that I am trying to run a check on are:
B25:B47, B50:B61, B64:B66, B86:B94,B103:B112,B114:B114,B116:B118,B120:b122,
etc. I named these group of cells oClearCells. Any help would be greatly
appreciated and very welcomed.
 
Hi Larry,

Try something like:

'=============>>
Public Sub Tester001()
Dim rng As Range

Set rng = Range("B25:B47, B50:B61, B64:B66, B86:B94," _
& "B103:B112,B114:B114,B116:B118,B120:b122")

If Application.CountA(rng) = 0 Then
'Your code
Else
MsgBox "All the cells are not empty!"
End If
End Sub
'<<=============
 
Back
Top