Copy/Paste Multiple Columns in VBA which has Picklist

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.



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:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top