ukbulldog001
New Member
- Joined
- Jul 8, 2015
- Messages
- 26
- Office Version
- 2016
- Platform
- Windows
Dear MrExcelites,
Need your help in modifying below macro to count hyphenated range as below.
Below is the result what I'm getting as of now with above code.
Below is the required result where the count should be 11 instead of 5
Can we use the numeric part of C074-C080 to derive the result as 11 like 074-080=7 count.
Need your help in modifying below macro to count hyphenated range as below.
VBA Code:
Sub ConcatenateRefDesignator()
Dim a, w
Dim i&
a = Cells(2, 1).CurrentRegion
With CreateObject("scripting.dictionary")
For i = 2 To UBound(a)
If Not .exists(a(i, 1)) Then
.Add a(i, 1), Array(a(i, 1), a(i, 2), 1)
Else
w = .item(a(i, 1))
w(1) = w(1) & "," & a(i, 2): w(2) = w(2) + 1
.item(a(i, 1)) = w
End If
Next
Range("E3").Resize(.count, 3) = Application.Index(.items, 0, 0)
End With
End Sub
Below is the result what I'm getting as of now with above code.
CPN | REF DES | CPN | REF DES | Count | ||
0654-9401-05 | C001 | 0654-9401-05 | C001,C002,C074-C080,C011,C012 | 5 | ||
0654-9401-05 | C002 | 0656-9254-77 | C003,C008,C010,C013,C014,C015,C017 | 7 | ||
0656-9254-77 | C003 | 0654-9431-01 | C005 | 1 | ||
0654-9401-05 | C074-C080 | 0657-9051-06 | C007 | 1 | ||
0654-9431-01 | C005 | 0654-8411-04 | C009 | 1 | ||
0657-9051-06 | C007 | 0659-9111-54 | C018,C019,C020 | 3 | ||
0656-9254-77 | C008 | |||||
0654-8411-04 | C009 | |||||
0656-9254-77 | C010 | |||||
0654-9401-05 | C011 | |||||
0654-9401-05 | C012 | |||||
0656-9254-77 | C013 | |||||
0656-9254-77 | C014 | |||||
0656-9254-77 | C015 | |||||
0656-9254-77 | C017 | |||||
0659-9111-54 | C018 | |||||
0659-9111-54 | C019 | |||||
0659-9111-54 | C020 | |||||
Below is the required result where the count should be 11 instead of 5
CPN | REF DES | CPN | REF DES | Count | ||
0654-9401-05 | C001 | 0654-9401-05 | C001,C002,C074-C080,C011,C012 | 11 | ||
0654-9401-05 | C002 | 0656-9254-77 | C003,C008,C010,C013,C014,C015,C017 | 7 | ||
0656-9254-77 | C003 | 0654-9431-01 | C005 | 1 | ||
0654-9401-05 | C074-C080 | 0657-9051-06 | C007 | 1 | ||
0654-9431-01 | C005 | 0654-8411-04 | C009 | 1 | ||
0657-9051-06 | C007 | 0659-9111-54 | C018,C019,C020 | 3 | ||
0656-9254-77 | C008 | |||||
0654-8411-04 | C009 | |||||
0656-9254-77 | C010 | |||||
0654-9401-05 | C011 | |||||
0654-9401-05 | C012 | |||||
0656-9254-77 | C013 | |||||
0656-9254-77 | C014 | |||||
0656-9254-77 | C015 | |||||
0656-9254-77 | C017 | |||||
0659-9111-54 | C018 | |||||
0659-9111-54 | C019 | |||||
0659-9111-54 | C020 | |||||
Can we use the numeric part of C074-C080 to derive the result as 11 like 074-080=7 count.