Solved

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

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

770 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