Solved

Remove comma if no data found

Posted on 2016-08-04
4
35 Views
Last Modified: 2016-08-05
How do I modify the following to handle if the results only return a comma, to remove the comma.

=VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],5,FALSE) & ", " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],6,FALSE) & "  " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],7,FALSE)

results = City, ST  ZipCode
0
Comment
Question by:Karen Schaefer
4 Comments
 
LVL 7

Expert Comment

by:Phil Davidson
ID: 41743538
I would try this:

=IF(LEFT(A1,2)=",",SUBSTITUTE(A1,",",""),IF(RIGHT(A1,2)="--",SUBSTITUTE(A1,",",""), A1))

I got the idea from one of the answers here.  If a comma is the right most character and left most character, one comma will be replaced with nothing.
0
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 41743552
also can try:
=TRIM( IF( VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],5,FALSE) = "" , "", VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],5,FALSE) & ", " ) & VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],6,FALSE) & "  " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],7,FALSE) )

Open in new window

0
 
LVL 4

Assisted Solution

by:Alexandre Michel
Alexandre Michel earned 250 total points
ID: 41744106
you can use this formula

IF ( X = "," , "" , X )

if X is a comma return nothing otherwise return X itself


replace X with VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],5,FALSE) & ", " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],6,FALSE) & "  " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],7,FALSE)

and it becomes

IF ( VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],5,FALSE) & ", " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],6,FALSE) & "  " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],7,FALSE) = "," , "" , VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],5,FALSE) & ", " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],6,FALSE) & "  " &VLOOKUP(MainFormTbl[Company Name],BillingInfo[#All],7,FALSE) )

Alex
0
 

Author Closing Comment

by:Karen Schaefer
ID: 41744422
thanks for the great suggestion.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel User Form VBA Help 18 30
Find and Replace Function not working in Excel 13 43
Extract Unique List when in Two Columns in Excel 20 26
Excel VBA 4 26
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

786 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