Feb 19 2024 10:17 PM
hi all,
i need to check validation while pasting a row , for all column having drop down such that value for drop down must be from drop down list else it should give msg for error while allowing other cell values to paste
can someone help me with this?
thanks for your help
Feb 20 2024 12:01 AM
You can achieve this by using a combination of Excel's Data Validation feature and a VBA macro.
Here is a step-by-step guide:
1. Set up Data Validation:
2. Write a VBA Macro:
Vba Code is untested, please backup your file.
Sub PasteWithValidationCheck()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim isValid As Boolean
' Specify the worksheet and range where you have your dropdown lists
Set ws = ThisWorkbook.Sheets("Sheet1")
Set rng = ws.Range("A1:A5") ' Adjust range as needed
' Check if the pasted values are valid based on data validation
isValid = True
For Each cell In rng
If Not cell.Validation.Value(cell.Value) Then
isValid = False
Exit For
End If
Next cell
' If any cell contains an invalid value, display an error message
If Not isValid Then
MsgBox "One or more cells contain invalid values!", vbExclamation
Exit Sub
End If
' If all values are valid, proceed with pasting
On Error Resume Next
ws.Paste Destination:=ws.Range("A" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1)
On Error GoTo 0
If Err.Number <> 0 Then
MsgBox "Unable to paste values!", vbExclamation
End If
End Sub
3. Assign the Macro to a Button:
4. Testing:
This setup ensures that only rows with valid dropdown values are pasted, preventing invalid data from being entered into your worksheet. Adjust the ranges and sheet names in the code to match your specific workbook.The text, steps and the code were edited with the help of AI.
Note: If you use Excel Online (Excel for the web) have limited support for VBA macros, and certain features like assigning macros to buttons or running VBA code directly within the worksheet are not available. Additionally, the ability to interact with the Excel application via VBA is not available in the online versions. In Excel Online, you can use some basic formulas and functionalities, but advanced features like VBA macros are not supported. As a result, achieving the same functionality as described in the solution may not be possible directly in Excel Online. You need a desktop version to integrate the macro into the file and then use it in Excel Online (possibly with restrictions).
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.