+ Reply to Thread
Results 1 to 5 of 5

finding nonblank cells and reporting their addresses

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2009
    Location
    Plainsboro, NJ
    MS-Off Ver
    Excel 2003
    Posts
    3

    finding nonblank cells and reporting their addresses

    Hi! New to the forum; hoping someone can help me out.

    I have a pretty big worksheet (230 columns x over a thousand rows). Any given column might have 3-4 nonblank cells; the rest are blank.

    What I want to do for each column is obtain the address of each nonblank cell, then grab the contents of the corresponding cell in the B column and concatenate the results.

    In the attached example, I want to put the function in d2, and the expected result would be ar 001, fc 001, hw 003.

    Any help is very much appreciated! :-)
    Attached Files Attached Files
    Last edited by kevinwc1969; 11-18-2009 at 01:57 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: finding nonblank cells and reporting their addresses

    Welcome to the forum.

    If you're amenable to VBA, you can add this function to your workbook:
    Function Cat(vInp As Variant, _
                 Optional sSep As String = "", _
                 Optional bCatEmpty As Boolean = False) As String
        ' Catenates the elements of vInp separated by sSep
        ' Empty values and null strings are ignored unless bCatEmpty is True
    
        Dim vItem       As Variant
        Dim sItem       As String
    
        If bCatEmpty Then
            For Each vItem In vInp
                Cat = Cat & CStr(vItem) & sSep
            Next vItem
    
        Else
            For Each vItem In vInp
                sItem = CStr(vItem)
                If Len(sItem) Then Cat = Cat & sItem & sSep
            Next vItem
        End If
    
        If Len(Cat) Then Cat = Left(Cat, Len(Cat) - Len(sSep))
    End Function
    Then in D2, =Cat(IF(D4:D18<>"",$B4:$B18,""), ", ")

    The formula MUST be confirmed with Ctrl+Shift+Enter.

    Then you can copy across.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-17-2009
    Location
    Plainsboro, NJ
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: finding nonblank cells and reporting their addresses

    shg,

    Thanks for the welcome, and for the quick reply!

    I've done some VBA in Word, but not much in Excel, so I'm not sure whether I'm doing it right. I'm getting a #NAME? error in the spreadsheet. Apologies if I'm doing something silly or n00bish...

    I opened the Visual Basic editor, went to "This Workbook" under the file (VU demo.xls), and pasted in the function code. I then hit Save, went to the spreadsheet, pasted in the function call you provided, and did F2 | Ctrl-Shift-Enter. The cell then reads #NAME?.

    When I click on the error tooltip and select Show Calculation Steps, it looks like it's doing everything right (reading the column, finding the nonblank cells, pulling the right stuff from column B), but that it doesn't recognize Cat.

    I suspect that what I'm doing wrong is something obvious... did I put the function code in the wrong place? Or maybe it's a security setting, or something? I have Macro Security set to Medium (in case that might be relevant).

    Thanks again for your help--I really appreciate it.

  4. #4
    Registered User
    Join Date
    11-17-2009
    Location
    Plainsboro, NJ
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: finding nonblank cells and reporting their addresses

    Never mind previous post--got it. I had, in fact, put the function code in the wrong place, but this page steered me right.

    Looks like I'm in business. Thanks!

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: finding nonblank cells and reporting their addresses

    Great. Would you please take a minute to read the forum rules, and then mark the thread as SOLVED?

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1