• 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.

Validate Range of Cells dynamically using VBA

Sai Prabhu

New Member
Hi,

I’m new to VBA and need help on the below questions. Sample file included.

Question - 1:

I’m working on a Leave Tracker and the requirement is that the User should not enter CL in more than two consecutive cells in rows.

CL CL CL - Not Allowed (pass with current code)

CL CL Blank CL CL - Allowed

CL CL CL CL CL CL - Not Allowed (failed with current code)

The code is working when the User enter data in each cell, however, it fails when the User copies data to range of Cells (More than 3 Cells).

Question - 2:

When the Excel file is opened from Outlook, how to disable Protected View message and Enable Editing programmatically? I tried few solutions available online, but that is not working.

Thanks.
 

Attachments

  • Test1.xlsm
    19.7 KB · Views: 3
You can also employ conditional formatting also.

1. Select all applicable ranges (first two columns can be excluded).
2. Then in conditional formatting box put in formula : =AND(C1="CL",COUNTIF(OFFSET(C1,0,-2,1,2),"CL")=2)
3. Apply conditional formatting as you want.

It will highlight incorrectly filled cell.
 

Attachments

  • Test1.xlsm
    17.4 KB · Views: 2
Back
Top