Solved

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

Posted on 2014-10-28
2
446 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 50

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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