I am happy to use VBA if someone will explain it to me first...
I was also aware of the concatenate operation, but in this case I'd prefer to use something less manual, as I don't have an exact count of the numbers in the row. There may be 2 numbers to string together, or there may be 20. So I need to limit it without having a bunch of commas appearing at the end.
You don't. You either use VBA or a different kind of formula.
Assuming your data is in A1:A3000, in cell B1 put =A1
In cell B2 put =B1&","&A2 and then just copy down to B3000 (Hover the mouse over the bottom right corner of the cell and double click).
Then select cell B3000, hit F2 then F9 and then enter
With 3000 entries you need to be careful that your average string length is not more than around 10 characters long, as you will run into problems with the amount of text the cell can hold. Max of 32,767 characters. Only 1,024 display in a cell; all 32,767 display in the formula bar.
For x = 1 To Rng.Rows.Count
str = str & "," & Rng.Rows(x).Value
Next x
Range("B1" = str
End Sub
1) Hit ALT+F11 to get you into the VBE
2) Find your project name in the explorer style interface at the top left pane of the VBE
3) Right click on your project and select 'insert module'
4) Double click on module1 when it appears, and then click into the big white space on the right of your screen when it appears.
5) Paste the code supplied into it
6) Hit File / Close and return to Microsoft Excel
7) Save Workbook
8) Hit Tools / Macros / Macro / Concat
Thanks for the VBA code. I'm using that so I don't have thousands of formulas where they're not required.
Can you perhaps help me expand the code so that it looks in another cell for a date?
My sheet looks something like this ::
A B C D E F
1 New ................ 18/06/02
2 Closed .............. 15/05/03
3 Open ................ 19/05/03
4 New ................. 12/06/03
5 New ................. 08/06/03
What I really need to do is select all the ID numbers (1-5 in the example), and concatenate them into a string separated by commas, where the relevant date is more than 5 days in the past, and where the cell shown has status New.
Currently I have a formula in the first 20 cells or so of column H which is :
Obviously with the first method you aren't actually stuck with the formulas as you can delete them, but I'd still prefer VBA for what you want anyway. Try the following, and just change the "B1" reference for whatever cell you want the data to appear in.
Sub Concat2()
Dim LastRw As Long
Dim Rng As Range
Dim str As String
For x = 1 To Rng.Rows.Count
If Rng.Rows(x).Value = "New" And _
Rng.Rows(x).Offset(0, 5).Value <= (Date - 5) Then
str = str & "," & Rng.Rows(x).Offset(0, 5).Value
End If
Next x
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.