过滤器 excel table 以获取唯一集
Filter excel table for unique sets
我有一个 excel table 看起来像这样:
Row Name
1 uniqueName001_vid1.mpg
2 uniqueName001.mpg
3 uniqueName002_vid1.mpg
4 uniqueName002_vid2.mpg
5 uniqueName002.mpg
我正在尝试找出如何在 table 中识别和标记(提供唯一 ID)集,其中包含相同的 uniqueName。例如,行的 1 和 2 将是一组,行的 3、4 和 5 将是另一组。
我理想的结果是这样的:
Row Name UID
1 uniqueName001_vid1.mpg SET1
2 uniqueName001.mpg SET1
3 uniqueName002_vid1.mpg SET2
4 uniqueName002_vid2.mpg SET2
5 uniqueName002.mpg SET2
我可以 运行 在 excel 中查询 SQL 如果这也是比 excel 公式更好的选择。
非常感谢任何建议!
如果所有都以 uniqueNameXXX 开头就容易了
Row Name UniqueName Unique# UID
1 uniqueName001_vid1.mpg =LEFT(F4;13) =IF(G3<>G4;H3+1;H3) ="UID"&H4
如果不是,那么您应该定义如何获取 uniqueName
您可以使用 VBA
完成该任务。
我为你做了一个小工具。照顾可编辑的部分
根据声明。
此工具侦听数字 - 意思是,我希望您的模式始终与您在问题中所写的相同。
告诉我这是否有帮助:
Sub ExtractIdFromString()
Dim strYourColumn As String
Dim intYourStartRow As Integer
Dim intYourLengthOfId As Integer
Dim strYourSetColumn As String
Dim strYourPrefix As String
Dim strString As String
Dim intStringLength As Integer
Dim intStringDigitPosition As Integer
Dim intParserPosition As Integer
Dim strParser As String
Dim i As Integer
Dim strUniqueString As String
Dim rngCell As Range
Dim rngSetCell As Range
Dim strIndex As String
Dim lngCounter As Long
''''editable values''''
strYourColumn = "B" 'Your name column, must be alphabethical
intYourStartRow = 1 'Startrow of your block, must not be 0
intYourLengthOfId = 3 'The amount of digits in your ID, must be > 1
strYourSetColumn = "C" 'The column, where the ID will be inserted, must be numerical (use A = 1, Z = 26)
strYourPrefix = "SET" 'Prefix of your set's ID
''''end of editable values''''
'Set the format of the ID column to text
Range(strYourColumn & ":" & strYourColumn).NumberFormat = "@"
'traverse through the names column
For Each rngCell In Range(strYourColumn & ":" & strYourColumn)
'initialize / reset parser
intParserPosition = 1
'get the actual string to value
strString = rngCell.Value
'End loop on empty cell
If strString = "" Then
GoTo massRename
End If
'get the string's length
intStringLength = Len(strString)
'parse through the string
For intStringDigitPosition = 1 To intStringLength Step 1
'end loop if the string is parsed without a result
If intParserPosition > intStringLength Then
Exit For
End If
'get single digit of the string
strParser = Mid(strString, intParserPosition, 1)
'listen on numbers
If IsNumeric(strParser) Then
'traverse through the expected ID slots
For i = intParserPosition To intParserPosition + intYourLengthOfId - 1 Step 1
'listen for non numerical chars in the expected ID
If Not IsNumeric(Mid(strString, i, 1)) Then
'allow your titles to include numbers
GoTo SkipSingleNumerics
End If
Next
'get the unique prototype of the string
strUniqueString = Mid(strString, 1, intParserPosition + intYourLengthOfId - 1)
'write the unique name in a specified column
Range(strYourSetColumn & rngCell.Row).Value = strUniqueString
End If
'Skip numbers in the string, that dont dont match the ID pattern (optional)
SkipSingleNumerics:
'traverse trough the word
intParserPosition = intParserPosition + 1
Next
Next
'Rename and index equal values
massRename:
lngCounter = 1
'traverse through the set list
For Each rngSetCell In Range(strYourSetColumn & ":" & strYourSetColumn)
'end condition
If rngSetCell.Value = "" Then
Exit For
End If
'store value in variable to save it from overwriting
strIndex = rngSetCell.Value
'start another traversal instance
For Each rngCell In Range(strYourSetColumn & ":" & strYourSetColumn)
'end condition
If rngCell.Value = "" Then
Exit For
End If
'listen if both instances match
If strIndex = rngCell.Value Then
'rename the value
rngCell.Value = strYourPrefix & lngCounter
End If
Next
'increase unique counter
lngCounter = lngCounter + 1
Next
End Sub
2010 年 Excel 测试
我有一个 excel table 看起来像这样:
Row Name
1 uniqueName001_vid1.mpg
2 uniqueName001.mpg
3 uniqueName002_vid1.mpg
4 uniqueName002_vid2.mpg
5 uniqueName002.mpg
我正在尝试找出如何在 table 中识别和标记(提供唯一 ID)集,其中包含相同的 uniqueName。例如,行的 1 和 2 将是一组,行的 3、4 和 5 将是另一组。
我理想的结果是这样的:
Row Name UID
1 uniqueName001_vid1.mpg SET1
2 uniqueName001.mpg SET1
3 uniqueName002_vid1.mpg SET2
4 uniqueName002_vid2.mpg SET2
5 uniqueName002.mpg SET2
我可以 运行 在 excel 中查询 SQL 如果这也是比 excel 公式更好的选择。
非常感谢任何建议!
如果所有都以 uniqueNameXXX 开头就容易了
Row Name UniqueName Unique# UID
1 uniqueName001_vid1.mpg =LEFT(F4;13) =IF(G3<>G4;H3+1;H3) ="UID"&H4
如果不是,那么您应该定义如何获取 uniqueName
您可以使用 VBA
完成该任务。
我为你做了一个小工具。照顾可编辑的部分 根据声明。
此工具侦听数字 - 意思是,我希望您的模式始终与您在问题中所写的相同。
告诉我这是否有帮助:
Sub ExtractIdFromString()
Dim strYourColumn As String
Dim intYourStartRow As Integer
Dim intYourLengthOfId As Integer
Dim strYourSetColumn As String
Dim strYourPrefix As String
Dim strString As String
Dim intStringLength As Integer
Dim intStringDigitPosition As Integer
Dim intParserPosition As Integer
Dim strParser As String
Dim i As Integer
Dim strUniqueString As String
Dim rngCell As Range
Dim rngSetCell As Range
Dim strIndex As String
Dim lngCounter As Long
''''editable values''''
strYourColumn = "B" 'Your name column, must be alphabethical
intYourStartRow = 1 'Startrow of your block, must not be 0
intYourLengthOfId = 3 'The amount of digits in your ID, must be > 1
strYourSetColumn = "C" 'The column, where the ID will be inserted, must be numerical (use A = 1, Z = 26)
strYourPrefix = "SET" 'Prefix of your set's ID
''''end of editable values''''
'Set the format of the ID column to text
Range(strYourColumn & ":" & strYourColumn).NumberFormat = "@"
'traverse through the names column
For Each rngCell In Range(strYourColumn & ":" & strYourColumn)
'initialize / reset parser
intParserPosition = 1
'get the actual string to value
strString = rngCell.Value
'End loop on empty cell
If strString = "" Then
GoTo massRename
End If
'get the string's length
intStringLength = Len(strString)
'parse through the string
For intStringDigitPosition = 1 To intStringLength Step 1
'end loop if the string is parsed without a result
If intParserPosition > intStringLength Then
Exit For
End If
'get single digit of the string
strParser = Mid(strString, intParserPosition, 1)
'listen on numbers
If IsNumeric(strParser) Then
'traverse through the expected ID slots
For i = intParserPosition To intParserPosition + intYourLengthOfId - 1 Step 1
'listen for non numerical chars in the expected ID
If Not IsNumeric(Mid(strString, i, 1)) Then
'allow your titles to include numbers
GoTo SkipSingleNumerics
End If
Next
'get the unique prototype of the string
strUniqueString = Mid(strString, 1, intParserPosition + intYourLengthOfId - 1)
'write the unique name in a specified column
Range(strYourSetColumn & rngCell.Row).Value = strUniqueString
End If
'Skip numbers in the string, that dont dont match the ID pattern (optional)
SkipSingleNumerics:
'traverse trough the word
intParserPosition = intParserPosition + 1
Next
Next
'Rename and index equal values
massRename:
lngCounter = 1
'traverse through the set list
For Each rngSetCell In Range(strYourSetColumn & ":" & strYourSetColumn)
'end condition
If rngSetCell.Value = "" Then
Exit For
End If
'store value in variable to save it from overwriting
strIndex = rngSetCell.Value
'start another traversal instance
For Each rngCell In Range(strYourSetColumn & ":" & strYourSetColumn)
'end condition
If rngCell.Value = "" Then
Exit For
End If
'listen if both instances match
If strIndex = rngCell.Value Then
'rename the value
rngCell.Value = strYourPrefix & lngCounter
End If
Next
'increase unique counter
lngCounter = lngCounter + 1
Next
End Sub
2010 年 Excel 测试