I have a data validation list value which my macro will copy data to a specific place in the workbook based on this value. However, when a value is selected from the data validation list the macro skips the IF statement, as if the statement is false. Could you please help me understand why this is happening? If I remove the data validation, the macro works as expected. Thank You!
Sub AddToList()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow1 As Long
Dim lRow2 As Long
Dim lRow3 As Long
Dim lRow4 As Long
Application.ScreenUpdating = False
Set ws1 = ThisWorkbook.Worksheets("DILUTION CALCULATOR")
Set ws2 = ThisWorkbook.Worksheets("SETUP")
lRow1 = ws2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
lRow2 = ws2.Cells(Rows.Count, 5).End(xlUp).Offset(1, 0).Row
lRow3 = ws2.Cells(Rows.Count, 9).End(xlUp).Offset(1, 0).Row
lRow4 = ws2.Cells(Rows.Count, 13).End(xlUp).Offset(1, 0).Row
If ws1.Range("M4") = "" Or ws1.Range("O4") = "" Or ws1.Range("Q4") = "" Then
MsgBox "Please Enter Data In All Fields", vbCritical
Exit Sub
ElseIf ws1.Range("M4") = "Customer" Then
ws1.Range("O4 , Q4").Copy
ws2.Cells(lRow1, 1).PasteSpecial Paste:=xlValues
ElseIf ws1.Range("M4") = "Order Number" Then
ws1.Range("O4 , Q4").Copy
ws2.Cells(lRow2, 5).PasteSpecial Paste:=xlValues
ElseIf ws1.Range("M4") = "Quantity" Then
ws1.Range("O4 , Q4").Copy
ws2.Cells(lRow3, 9).PasteSpecial Paste:=xlValues
ElseIf ws1.Range("M4") = "Status" Then
ws1.Range("O4 , Q4").Copy
ws2.Cells(lRow4, 13).PasteSpecial Paste:=xlValues
End If
ws1.Range("M4, O4, Q4").ClearContents
Application.ScreenUpdating = True
End Sub