top of page

You are learning Data Validation in MS Excel

How to validate data based on another cell's value from a different workbook?

Unfortunately, Excel's built-in Data Validation feature doesn't directly work across different workbooks. However, there are a couple of workarounds you can use to achieve data validation based on another cell's value in a separate workbook:

Method 1: Indirect Formula with Conditional Formatting (One-way validation)

1. Link the value from the other workbook: In your current workbook, use an indirect formula to reference the cell containing the validation criteria in the other workbook. The formula would look something like this (assuming the value is in cell A1 of Sheet1 in "Criteria.xlsx"):

```excel
=INDIRECT("'" & "[Criteria.xlsx]Sheet1!A1" & "'")
```

2. Conditional Formatting: Apply conditional formatting to the cell you want to validate. Set the rule to format the cell based on the value retrieved from the indirect formula.

- For example: If the value from the other workbook is "TRUE", format the cell green (valid), and if it's "FALSE", format it red (invalid).

Note: This method provides a visual cue for valid/invalid data but doesn't prevent users from entering invalid values.

Method 2: VBA Macro (Two-way validation with error message)

1. Write a VBA macro: This method requires creating a macro that checks the value in the other workbook before allowing data entry. The macro can display a message box with an error message if the entered data doesn't meet the criteria.

The macro would involve:
- Referencing the other workbook cell using VBA functions like `Workbooks("Criteria.xlsx").Worksheets("Sheet1").Range("A1").Value`
- Checking the entered data against the retrieved value.
- Displaying an error message if invalid and potentially clearing the cell content.

2. Assign the macro to a cell event: Assign the macro to run whenever a user tries to edit the cell you want to validate (e.g., using the `Worksheet_Change` event).

This method offers a more robust solution with real-time validation and error prevention. However, it requires some familiarity with VBA coding.

Additional Considerations:

* Both methods rely on the other workbook being open for the validation to work.
* Changes to the validation criteria in the other workbook would require updating the formula or macro accordingly.

Choose the method that best suits your needs and technical expertise. If you're not comfortable with VBA, the conditional formatting approach might be a simpler solution.

bottom of page