+ Reply to Thread
Results 1 to 12 of 12

Calculate non-empty rows for concatenation

Hybrid View

Internoob2 Calculate non-empty rows for... 08-23-2011, 10:13 AM
Marcol Re: Calculate non-empty rows... 08-23-2011, 10:26 AM
Internoob2 Re: Calculate non-empty rows... 08-23-2011, 10:43 AM
Marcol Re: Calculate non-empty rows... 08-23-2011, 10:52 AM
Internoob2 Re: Calculate non-empty rows... 08-23-2011, 11:24 AM
Internoob2 Re: Calculate non-empty rows... 08-23-2011, 11:31 AM
Internoob2 Re: Calculate non-empty rows... 08-23-2011, 11:54 AM
Marcol Re: Calculate non-empty rows... 08-23-2011, 12:41 PM
Internoob2 Re: Calculate non-empty rows... 08-26-2011, 10:01 AM
snb Re: Calculate non-empty rows... 08-26-2011, 10:11 AM
saurav.falia Re: Calculate non-empty rows... 08-27-2011, 01:18 AM
Internoob2 Re: Calculate non-empty rows... 09-03-2011, 12:25 AM
  1. #1
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Red face Calculate non-empty rows for concatenation

    Hello,

    So I am having a bit of trouble figuring this out.

    What I want to do is calculate how many rows have data in column A (which I have been able to do), but then using that info I then want to concatenate that data with a ", " in between each value (which is where I am stuck). So the VBA should calculate say 3 values (last value in A3, first data always in A1), then concatenate those values (v1, v2, v3) to be copied and special pasted (just values into a selected cell on another sheet) without needing to hard code the formulas on the worksheet.

    For the time being I have physically typed in the concatenate formulas (for 2 values, 3, etc up to 6 values - since there is usually not more than 6 for now) and manually select the row with the correct amount of values.

    Any help would be greatly appreciated as it would make this project immensley easier.

    Thanks,

    -BC
    Attached Images Attached Images
    Last edited by Internoob2; 08-26-2011 at 10:01 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Calculate non-empty rows for concatenation

    See if this workbook gives you some ideas.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Re: Calculate non-empty rows for concatenation

    Unfortunately this does not adress my VBA question. I understand how to hard code concatenation into a worksheet.

    What I need help with is conditionally concatenating varying range sizes in VBA. (Also I am using 2007 and Conc does not seem to be a valid function anymore)

    I do appreciate the reply however.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Calculate non-empty rows for concatenation

    That is a VBa solution, just used as a UDF. it isn't a standard Excel Formula.

    Why not post a sample workbook showing your typical data and how you need it to end up?
    A picture with only 3 or 4 rows is not enough to explain your problem clearly.

  5. #5
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Re: Calculate non-empty rows for concatenation

    Sorry, I consider myself an intermediate noob with VBA and was not sure what UDF was.

    Please bear with me.

    If you could spell out precisely what I need to do it would help me a lot. I thought this would be pretty simple to achieve but it is proving more complicated than I imagined.

    My issue is that there could be 2 values, 3, or perhaps even 6. I want to write a macro that will calulate the number of values in Coulmn A and concatenate them with a comma and space the be pasted in column D on the first sheet. And again it will not always be the same number of values to concatenate.

    Perhaps if you can post the actual vba code you use it may clear up my confusion, I do see the vba function now,so I apologize for that.

    So it seems my question is how to calculate and pass the varying range to the function.


    I really do appreciate the help not trying to make you mad, it's just the noob in me.


    -BC

    P.S. So I made a copy of the actual sheet I am using (with my ghetto fabulous solution). 1. I select the cell in column E on the first page.
    2. I paste in the multiple values on the second sheet in Column A
    3. They are concatenated in column F
    4. I select the row with the correct number of values in F
    5. Run my little macro (ctrl+f) to paste values into the initial cell on the 1st sheet.

    Would love if I could automate steps 3-5, after pasting the values just run a macro that will concatenate the proper number of values and paste them right into the first sheet.

    I hope that this will make my thoughts a bit clearer.
    Attached Files Attached Files
    Last edited by Internoob2; 08-23-2011 at 11:26 AM.

  6. #6
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Re: Calculate non-empty rows for concatenation

    Btw the conc UDF works perfectly, thank you for that too!

    -BC

  7. #7
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Talking Re: Calculate non-empty rows for concatenation

    Good enough.

    With your brilliant Conc UDF I was able to fit all the steps into a single macro.

    I am curious though, is there a way to use the conc function within a vba sub, or does it have to be used on the worksheet itself?


    Thank you, thank you, thank you! It may seem insignificant for you but you have helped me so much with this tiny UDF.

    -BC

    P.S. I did not initially realize conc would only add the seperator if there was another value. now I:
    1. Paste values in column A
    2. Run my little macro ctrl+f and it formats, copies the conc concatenated value from f2 and pastes the values into 1st sheet.

    Love it. How can i ever repay you?
    Attached Files Attached Files

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Calculate non-empty rows for concatenation

    Here is what I tried to get a draggable formula.

    In a standard module
    Option Explicit

    Function Conc(RangeAddress As String, Optional Separator As String = "")
        Dim Cell As Range, rng As Range
        
        Set rng = Range(RangeAddress)
        For Each Cell In rng
            If Cell <> "" Then
                ConcBeforeBlank = ConcBeforeBlank & Separator & Cell
            End If
        Next
        If Separator <> "" Then
            ConcBeforeBlank = Right(ConcBeforeBlank, Len(ConcBeforeBlank) - Len(Separator))
        End If
    End Function
    Put this in A2 (With your Data in Column B starting Row 2)
    =IF(B2="","",IF(ISNUMBER(A1),1+A1,1))
    Drag/Fill Down

    In D2
    =IF(B2="","",IF(B3="",concBeforeBlank("B"&ROW()-A2+1&":B"&ROW(),", "),""))
    Drag/Fill Down

    This will return a concatenation of the rows that are separated by blanks.

    Hope this helps.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Re: Calculate non-empty rows for concatenation

    Thank you for your help on this. It has definitely helped me cut out some repetitive mouse clicks and keyboard shoertcuts.

    Cheers,
    -BC

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Calculate non-empty rows for concatenation

    or

    Sub snb()
     For Each ar In Sheets("Multiple paste Values").Columns(2).SpecialCells(2).Areas
      ar.Cells(ar.Cells.Count).Offset(, 2) = Join(Application.Transpose(ar), ",")
     Next
    End Sub



  11. #11
    Registered User
    Join Date
    09-23-2009
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    3

    Red face Re: Calculate non-empty rows for concatenation

    Hello Internoob2,

    Please check out the macro, in the attached sheet. You have to go to the sheet named "Multiple paste Values", and make sure u do not delete this sheet, as the macro is based on this sheet. You also do not delete or modify the 1st row in the sheet, the reason being the same.

    U need to enter the data in column A, and the click the "Run Macro"button.

    Enjoy......!!!

    Please provide your valuable feedback.

    Regards,
    Saurav.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Wink Re: Calculate non-empty rows for concatenation

    Cool, thank you for being so thorough.

    My one tweak I mentioned I would be tohave the concatenated string always printed to the same cell.

    In this application there will always only be one list of values (as opposed to 2 or 3 sets).

    So for instance, the values from the first block to print to C2 (instead of C4 the row of the last value in Column A). Again that is just for my purposes in this specific application.

    I think your code is quite clever and certainly can think of some uses for it.

    Thank you for your time and help,
    -BC


    P.S. I am about to post a different, VB to VBA post if you feel like helping an "internoobiate" along the way.

+ 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