• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

shortening a vba code

iceblocks

Member
Hi all,
I have written a code and it works fine, but for my learning purposes is there a way to simplify this code...

Code:
If Len(Range("J10")) = 0 Or Len(Range("J14")) = 0 Or Len(Range("J29")) = 0 Or Len(Range("L10")) = 0 Or Len(Range("L14")) = 0 Or Len(Range("L29")) = 0 Then

Many thanks.
iceblocks
 
Iceblocks

setup a named formula as
myRng: =Sheet1!$J$10,Sheet1!$L$10,Sheet1!$J$14,Sheet1!$L$14,Sheet1!$J$29,Sheet1!$L$29

Then in VBA
Code:
If Application.WorksheetFunction.CountA([MyRng]) <> 6 Then ...
 
Hi ,

As an alternative you can do this within VBA itself :
Code:
          Dim Rng As Range
          Set Rng = Union(Range("J10"), Range("J14"), Range("J29"), Range("L10"), Range("L14"), Range("L29"))
          If Application.WorksheetFunction.CountA(Rng) <> Rng.Cells.Count Then MsgBox "At least one blank cell"
Narayan
 
Back
Top