ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DV error message with a cell value (https://www.excelbanter.com/excel-programming/276571-dv-error-message-cell-value.html)

Soniya

DV error message with a cell value
 
Hi All,


Is it possible to get a cell value to be displayed as an
error meessage in a data validation?

for eg if i have limited the number in A1 to be equal or
multples of B1 how can i get an eror message somethinf
like "amount should be multples of " & B1.value
(the value in B1 may vary)

TIA
Soniya

Dave Peterson[_3_]

DV error message with a cell value
 
You could use an event macro to change the data validation error message
whenever you changed B1.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Range("b1")) Is Nothing Then Exit Sub

On Error GoTo errHandler:

With Range("a1")
If .Value Mod Target.Value < 0 Then
Application.EnableEvents = False
.ClearContents
End If
.Validation.ErrorMessage _
= "Must be a multiple of " & Target.Value & "."
End With

errHandler:
Application.EnableEvents = True
End Sub


Right click on the worksheet tab that should have this behavior. Select View
code and paste this in.

I also looked at the value in A1. If it's not a multiple of the current value
in B1, then it gets cleared. You may not want that.



Soniya wrote:

Hi All,

Is it possible to get a cell value to be displayed as an
error meessage in a data validation?

for eg if i have limited the number in A1 to be equal or
multples of B1 how can i get an eror message somethinf
like "amount should be multples of " & B1.value
(the value in B1 may vary)

TIA
Soniya


--

Dave Peterson



All times are GMT +1. The time now is 01:03 PM.

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