Completely Lost

LambVBA

New Member
Joined
Mar 28, 2014
Messages
16
Hi guys,

I'm completely fogged here and don't know where to begin. I have a table that I need to know a subtotal based on each order. Hopefully I can describe this correctly. Of the table below what I need as an output is the Order Number and how many distinct load numbers there are to each. So a result may be some sort of code which adds a column F with the distinct Order Number and column G with the total distinct amount of Load Numbers.
Load Number</SPAN>
Host External ID</SPAN>
Order Number</SPAN>
Carrier Move ID</SPAN>
Schedule Batch Number</SPAN>

<TBODY>
</TBODY>
00082126381</SPAN>
12345
XA82949</SPAN>
00863</SPAN>
2
00082139824</SPAN>
12345</SPAN>
XA82949</SPAN>
00863</SPAN>
</SPAN>
2

<TBODY>
</TBODY>
00010663629</SPAN></SPAN></SPAN>
12345</SPAN>
XA82949</SPAN>
00863</SPAN>
</SPAN>
2

<TBODY>
</TBODY>
00010553630</SPAN>
12345</SPAN>
TG12302</SPAN>
00863</SPAN>
2

<TBODY>
</TBODY>
00020663631</SPAN>
12345</SPAN>
WY12305</SPAN>
00863</SPAN>
2
00010663432</SPAN>
12345</SPAN>
WY12305</SPAN>
00863</SPAN>
2

<TBODY>
</TBODY>

<TBODY>
</TBODY>

<TBODY>
</TBODY>
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
LambVBA,

You did not show us what your results should look like.

If I understand you correctly.

Sample raw data in the active worksheet:


Excel 2007
ABCDEFG
1Load NumberHost Exteral IDOrder NumberCarrier Move IDSchedule Batch Numberdistinct Order Numbertotal Load Numbers
28212638112345XA829498632
38213982412345XA829498632
41066362912345XA829498632
51055363012345TG123028632
62066363112345WY123058632
71066343212345WY123058632
8
Sheet1


After the macro:


Excel 2007
ABCDEFG
1Load NumberHost Exteral IDOrder NumberCarrier Move IDSchedule Batch Numberdistinct Order Numbertotal Load Numbers
28212638112345XA829498632XA829493
38213982412345XA829498632TG123021
41066362912345XA829498632WY123052
51055363012345TG123028632
62066363112345WY123058632
71066343212345WY123058632
8
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub GetUniquesCount()
' hiker95, 10/28/2014, ME814635
Dim c As Range, rng As Range, n As Long, ki
With ActiveSheet
  Set rng = .Range("C2:C" & .Range("C" & Rows.Count).End(xlUp).Row)
  With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
    For Each c In rng
      If Not .Exists(c.Value) Then
        .Add c.Value, 1
      Else
        .Item(c.Value) = .Item(c.Value) + 1
      End If
    Next
    n = .Count
    ki = Application.Transpose(Array(.Keys, .Items))
  End With
  .Range("F2").Resize(n, 2) = ki
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the GetUniquesCount macro.
 
Upvote 0
LambVBA,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top