Solved

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

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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 …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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 …

708 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

10 Experts available now in Live!

Get 1:1 Help Now