kbay808
asked on
How to fix vba code to leave cell blank when the criteria is not met?
I have the below code in the attached example file. It searches for 3 different criteria. The problem is that when one of the criteria is met, the same result is listed for the remaining searches. How do I modify the code to leave the result blank if the particular criteria are not met? In the attached example the results are displayed in row “B”. The macro is triggered by a button on the page and 4 different test datasets are available in a dropdown menu found in cell C10. The desired results are shown in row “C”.
Sub Description_Data()
On Error Resume Next
Range("B2:B4").ClearContents
aLines = Split(Range("C10"), vbLf)
strTmp = Filter(aLines, "User Name:")(0)
Range("B2") = Trim(Split(strTmp, ":")(1))
strTmp = Filter(aLines, "POC:")(0)
Range("B3") = Trim(Split(strTmp, ":")(1))
strTmp = Filter(aLines, "Primary Contact:")(0)
Range("B4") = Trim(Split(strTmp, ":")(1))
End Sub
Example.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER