I have done this without much effort on T-SQL, but I want to implement the same on Excel VBA. How to achieve this? I have a field on my sheet called “Stops” which pertains to the Stops that a truck makes while delivering its order. I want to count the total number of stops. 1 stop can have multiple orders to be delivered. The data on the stops column is something like:
Order# Stops
1527305 1
1527305 1
1529418 2
1529418 2
1527299 3
1527299 3
1528894 5
1528894 5
1529529 6
1529529 6
1529518 7
1529518 7
1527522 8
1527522 8
So, the final count should be just 7 unique stops. The current code looks at the last row and takes it as the total stops (which is wrong). The code that I have right now is as follows:
ActiveCell.Offset(0, 7).Select ' H = stop number
Selection.Value = curStop 'sets stop number
If Selection.Value = 0 Then
ActiveCell.Offset(-1, 0).Select
curStop = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Selection.Value = curStop
End If
I have done something on T-SQL with one line of code, but dont know how to do this on Excel. Any help will be appreciated. Thanks!!
You can also try
as an array formula solution, assuming your data is in B2:B15. Array formulae are, of course, entered with a Ctrl + Shift + Enter, rather than an enter, so maybe your solution is slightly better 🙂
Also shouldn’t your question say the answer is 7 stops, and not 5???