Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

enter image description here I'm trying to make this Excel document but I want the AdminTimes for the same LastRxNo to be on the same line. So if the LastRxNo is the same, have one line and the AdminTime column will have multiple values. Here is a picture of what I want it to look like

enter image description here

Any ideas? I was thinking an IF function, but I'm not too familiar with Excel to get it to work.

enter image description here

It was just made in the Microsoft Query tool in Excel.

share|improve this question
can you explain 28409 and down, why they don't consolidate? the 7A-7P already is the same? – datatoo Jul 3 '12 at 4:24
I should have actually removed the 7A-7P AdminTimes. Everything is being pulled from a SQL table and the (Certain Time through another Time) are medications that are dosed every shift vs twice a day or three times a day. It doesn't matter if they get consolidated. I just need every LastRxNo that are the same to consolidate the AdminTimes into a single row. – Corde Parker Jul 3 '12 at 17:19
since it is pulled from a SQL table could you create a query there to do all of this consolidation? or do you need to clear these values in excel first, and then do it? – datatoo Jul 3 '12 at 17:28
It could be done either way I guess. I have limited knowledge in SQL. I can post the query though. – Corde Parker Jul 3 '12 at 17:32
You can create a function in SQL that will do all of this for you automatically, which may be much easier than a vba solution in excel. if you want to try that approach I can suggest links forums.devshed.com/ms-sql-development-95/… and an access example allenbrowne.com/func-concat.html Once you have a function such as this, the query is not too bad – datatoo Jul 3 '12 at 19:09
show 1 more comment

1 Answer

This is a rather quick and messy macro that leaves lots still to do, but you will get the idea. It also presumes your original sheet("Sheet1") is sorted by LastRxNo. If you had the ability to add and call a function in the SQLServer it would be a simpler, less error prone task. hope this helps get you started. it outputs to a sheet called "summary"

Sub conCatTimes()
Dim rx As String
Dim admTimes As String
Dim tmp As String
Dim i As Long
Dim LastRow As Long
LastRow = Sheets("Sheet1").Range("C" & ActiveSheet.Rows.Count).End(xlUp).Row
rx = ""
i = 1
For Each cell In Sheets("Sheet1").Range("C2:C" & LastRow)
    If rx <> cell Then
        rx = cell
        i = i + 1
        tmp = ""
    End If
tmp = cell.Offset(0, 11)
admTimes = admTimes + tmp + ", "
    If cell.Offset(1, 0) <> rx Then
        Sheets("summary").Range("A" & i) = rx
        Sheets("summary").Range("B" & i) = Left(admTimes, Len(admTimes) - 2)
        admTimes = ""
    End If
Next

End Sub
share|improve this answer
Thanks datatoo for the response. Yeah, it seems like a pretty messy macro. I would have hoped there was an easier way because I seem to be coming across things on multiple lines that I want to make into a single line on another type of report I'm trying to run. Does anybody else have any suggestions/solutions? – Corde Parker Jul 6 '12 at 17:14
"things on multiple lines that I want to make into a single line", like what? This only showed copying LastRxNumber but you could easily include everything else. If everything is the same except the adminTimes, this could get you there. But the ultimate easiest way is to create a function on the server itself that exports it the way you need – datatoo Jul 6 '12 at 17:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.