Forum Discussion
KanwalNo1
May 22, 2022Iron Contributor
Apply Validation in a Column D as soon as the Value is Selected in adjacent cell in Column C
Dear Experts, I request a VBA or Non-VBA solution to the following issue. As soon as a Value is selected in Column C (Bank Payment ID) of the TABLE "BankPymtDet" --validation is applied to adja...
- May 22, 2022
New version:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range If Target.CountLarge > 1 Then Exit Sub Set rng = Intersect(Me.ListObjects("BankPymtDet").ListColumns("Bank Payment ID").DataBodyRange, Target) If Not rng Is Nothing Then If rng.Value <> "" And rng.Offset(0, 1).Value = "" Then Application.EnableEvents = False rng.Offset(0, 1).Validation.Delete rng.Offset(0, 1).Validation.Add _ Type:=xlValidateList, _ Formula1:="=PayeeDetails" rng.Offset(0, 1).ColumnWidth = 60 Application.EnableEvents = True End If End If Set rng = Intersect(Me.ListObjects("BankPymtDet").ListColumns("Name of Payee").DataBodyRange, Target) If Not rng Is Nothing Then If rng.Value <> "" Then Application.ScreenUpdating = False Application.EnableEvents = False Application.DisplayAlerts = False rng.Validation.Delete rng.TextToColumns _ DataType:=xlDelimited, _ Tab:=False, _ Semicolon:=False, _ Comma:=False, _ Space:=False, _ Other:=True, OtherChar:="-", _ FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2)) rng.EntireColumn.AutoFit Application.DisplayAlerts = True Application.EnableEvents = True Application.ScreenUpdating = True End If End If End Sub
KanwalNo1
May 22, 2022Iron Contributor
Instead of splitting the text on the basis of - (hyphen) it is using SPACE as the delimiter ?
HansVogelaar
May 22, 2022MVP
New version:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
If Target.CountLarge > 1 Then Exit Sub
Set rng = Intersect(Me.ListObjects("BankPymtDet").ListColumns("Bank Payment ID").DataBodyRange, Target)
If Not rng Is Nothing Then
If rng.Value <> "" And rng.Offset(0, 1).Value = "" Then
Application.EnableEvents = False
rng.Offset(0, 1).Validation.Delete
rng.Offset(0, 1).Validation.Add _
Type:=xlValidateList, _
Formula1:="=PayeeDetails"
rng.Offset(0, 1).ColumnWidth = 60
Application.EnableEvents = True
End If
End If
Set rng = Intersect(Me.ListObjects("BankPymtDet").ListColumns("Name of Payee").DataBodyRange, Target)
If Not rng Is Nothing Then
If rng.Value <> "" Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
rng.Validation.Delete
rng.TextToColumns _
DataType:=xlDelimited, _
Tab:=False, _
Semicolon:=False, _
Comma:=False, _
Space:=False, _
Other:=True, OtherChar:="-", _
FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2))
rng.EntireColumn.AutoFit
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End If
End Sub- KanwalNo1May 22, 2022Iron ContributorThanks a Lot Hans !
It was lightening quick ! Looks to be doing fine at the moment.
Let me use the code in actual scenario.
Thank You So much Sir !
Sincere Regards
Kanwaljit