ShilpaDell
New Member
- Joined
- Oct 5, 2018
- Messages
- 1
Hi,
I am trying to validate e Values I am pasting Excel which has the columns of PickList.
If I know the copy and paste is multiple rows for single column .Below is the code. But if the paste is multiple columns and Rows how will it work?
and The columns 4 and 10 are only have picklist.
Please Help.Thanks in Advance
I am trying to validate e Values I am pasting Excel which has the columns of PickList.
If I know the copy and paste is multiple rows for single column .Below is the code. But if the paste is multiple columns and Rows how will it work?
and The columns 4 and 10 are only have picklist.
Code:
Public CurRange As Range
Public CheckReasonCodeRange As Range
Public CheckLegacyIDPrefix As Range
Public str As String
Dim va As Variant
Dim length As Integer
Private Sub Worksheet_Change(ByVal Target As Range)
Set CurRange = Target
Set CheckReasonCodeRange = Sheets("Codes").Range("A:A")
Set CheckLegacyIDPrefix = Sheets("Codes").Range("X:X")
'checks the current column is a drop down(Reason Codes) or not
If ActiveCell.Column = 4 Then
'Checks the Multiple rows copy paste
If Target.Cells.Count >= 1 Then
length = Target.Cells.Count
For i = 1 To length Step 1
If length = 1 Then
str = Target.Cells.Value2
If str = "" Then Exit Sub
Else
str = Target.Cells.Value2(i, 1)
If str = "" Then Exit Sub
End If
If IsError(Application.Match(str, CheckReasonCodeRange, 0)) Then
MsgBox ("The value You Enetered is not in Reason codes List Please Select Value from Drop Down List:" & str)
CurRange.ClearContents
Exit Sub
End If
Next
End If
End If
If ActiveCell.Column = 10 Then
'Checks the Multiple rows copy paste
If Target.Cells.Count >= 1 Then
length = Target.Cells.Count
For i = 1 To length Step 1
If length = 1 Then
str = Target.Cells.Value2
If str = "" Then Exit Sub
Else
str = Target.Cells.Value2(i, 1)
If str = "" Then Exit Sub
End If
If IsError(Application.Match(str, CheckLegacyIDPrefix, 0)) Then
MsgBox ("The value You Enetered is not in Reason codes List Please Select Value from Drop Down List:" & str)
CurRange.ClearContents
Exit Sub
End If
Next
End If
End If
End Sub
Please Help.Thanks in Advance
Last edited by a moderator: