Solved

How to fix vba code to leave cell blank when the criteria is not met?

Posted on 2014-10-28
2
398 Views
Last Modified: 2014-10-29
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

Open in new window

Example.xlsm
0
Comment
Question by:kbay808
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40410056
Hi,

pls try

Sub Description_Data()
On Error Resume Next
Range("B2:B4").ClearContents
aLines = Split(Range("C10"), vbLf)
strTmp = ""
strTmp = Filter(aLines, "User Name:")(0)
Range("B2") = Trim(Split(strTmp, ":")(1))
strTmp = ""
strTmp = Filter(aLines, "POC:")(0)
Range("B3") = Trim(Split(strTmp, ":")(1))
strTmp = ""
strTmp = Filter(aLines, "Primary Contact:")(0)
Range("B4") = Trim(Split(strTmp, ":")(1))


End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:kbay808
ID: 40410094
Works perfect!!!  Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now