Consulting

Results 1 to 10 of 10

Thread: Using Ampersand "Showing a Zero"

  1. #1
    VBAX Contributor
    Joined
    Jun 2009
    Posts
    110
    Location

    Using Ampersand "Showing a Zero"

    Hi,

    A bit of help pleezz.

    In a column with data from row 15 to 50. Each row/column cell has a formula that is fed from another sheet. Sometimes these rows have data sometimes they don't.

    What I am doing is using the ampersand (example,
    A15&", "&A16&", "&A17&", "&A18&", "&A19&", "&A20&", "&A21&", "&A22&", "&A23&", "&A24&", "&A25.............................&A49&", "&A50
    in cell A23 thru A50 there is no data and in the cell where I have the ampersand formula it shows as a ZERO.

    I must have them all in there becuz there could be data to be filled in later on.

    Any ideas?..

    Da K---

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I'm afraid I don't understand the question. Do you not want to see the zero?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    =IF(A15="","",A15&", ")&IF(A16="","",A16&", ")&....
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Contributor
    Joined
    Jun 2009
    Posts
    110
    Location

    Thanks...

    Quote Originally Posted by xld
    Try

    =IF(A15="","",A15&", ")&IF(A16="","",A16&", ")&....
    That will work for less than 7 Nested If's...., I thought about that but figured there some other easier way...

    I'm gonna have to nest the IF's using the & operator.......

    Is there a way for VBA code to do this...

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No it works for far more than that because they are not nested.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Contributor
    Joined
    Jun 2009
    Posts
    110
    Location
    Quote Originally Posted by xld
    No it works for far more than that becauyse they are not nested.
    Well, I tried it but it still shows the Zero Value.

     
    =IF(A15="","",A15&", ")&IF(A16="","",A16&", ")&IF(A17="","",A17&", ")&IF(A18="","",A18&", ")&IF
     
    (A19="","",A19&", ")&IF(A20="","",A20&", ")&IF(A21="","",A21&", ")&IF(A22="","",A22&", ")&IF
     
    (A23="","",A23&", ")&IF(A24="","",A24&", ")&IF(A25="","",A25&", ")
    COLOMBIA, Argentina, Chile, Ecuador, El Salvador, Guatemala, Mexico, Panama, Puerto Rico, 0, 0,



    Any other thoughts?
    Last edited by Aussiebear; 04-02-2023 at 04:58 PM. Reason: Adjusted the code tags

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    How about a UDF. Enter =ListItems(A23:A50)

    Function ListItems(data As Range)
    Dim Cel As Range, txt As String
    For Each Cel In data
       If Cel <> "" Then txt = txt & Cel & ", "
    Next
    ListItems = Left(txt, (Len(txt) - 2))
    End Function
    Last edited by Aussiebear; 04-02-2023 at 04:59 PM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Contributor
    Joined
    Jun 2009
    Posts
    110
    Location

    Still shows Zero Value

    Quote Originally Posted by mdmackillop
    How about a UDF. Enter =ListItems(A23:A50)

    Function ListItems(data As Range)
    Dim Cel As Range, txt As String
    For Each Cel In data
    If Cel <> "" Then txt = txt & Cel & ", "
    Next
    ListItems = Left(txt, (Len(txt) - 2))
    End Function

    Really Nice but it shows the Zero value as well.

    Any other thought....

    Thanks...
    Last edited by Aussiebear; 04-02-2023 at 04:59 PM. Reason: Adjusted the code tags

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It can't do, there must be something else going on that you aren't telling us about.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Contributor
    Joined
    Jun 2009
    Posts
    110
    Location

    OK, I Think It's Ok Now

    Quote Originally Posted by xld
    It can't do, there must be something else going on that you aren't telling us about.
    On Sheet named "Program" Column A15 thru A50 cells each has a formula like this:

    A15 [ ='SchedulesFees'!A15]
    A16 [ ='SchedulesFees'!A16]
    ....................
    A50 [ ='SchedulesFees'!A50]

    that comes from sheet SchedulesFees.

    Not all of the cells in sheet SchedulesFees will have data all the time.

    In this case that we were trying to solve only 10 cells contained data and the rest did not. Those that did not are the ones that are shoing up as a Zero Value when using the apmersand and or UDF code that was provided.

    So, to get around this I did the following:

    On the sheet "Program" A15 I entered the following and copied on to the rest of the rows:

    =IF('SchedulesFees'!A24=0,"",'SchedulesFees'!A24)
    This allowed me to use both XLD ampersand format and mdmackillop VBA Code as well.

    It works... Now the zeros do not show...

    Thanx to all of for your help...
    Last edited by Aussiebear; 04-02-2023 at 05:00 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •