我正在尝试将Pokemon数据库规范化为1NF,但是,我不确定如何在Excel中执行此操作。
我想在“能力”中获取多个数据条目,并拆分它们并复制该行。
原始数据
for(int i = 0; i != n_block; ++i){
ps[i] = A.allocate(block_size); //eventually throws, but HERE
for(long j = 0; j != block_size; ++j){
A.construct(ps[i] + j, 'z');
}
}
所需数据
+----------------+-----------+---------------+-----------------------------+
| pokedex_number | name | classfication | abilities |
+----------------+-----------+---------------+-----------------------------+
| 1 | Bulbasaur | Seed Pokemon | ['Overgrow', 'Chlorophyll'] |
| 2 | Ivysaur | Seed Pokemon | ['Overgrow', 'Chlorophyll'] |
| 3 | Venusaur | Seed Pokemon | ['Overgrow', 'Chlorophyll'] |
+----------------+-----------+---------------+-----------------------------+
答案 0 :(得分:0)
您可以尝试:
Option Explicit
Dim strResults As String
Sub test()
Dim varSplit As Variant
Dim LastRow As Long, i As Long, Counter As Long, y As Long, CounterArr As Long
Dim pokedex_number As String, name As String, classfication As String
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 2 Step -1
Counter = Len(.Range("D" & i).Value) - Len(Replace(.Range("D" & i).Value, ",", ""))
If Counter > 0 Then
Call Module1.Clean(.Range("D" & i).Value)
varSplit = Split(strResults, ",")
pokedex_number = .Range("A" & i).Value
name = .Range("B" & i).Value
classfication = .Range("C" & i).Value
.Rows(i + 1 & ":" & i + Counter).Insert
CounterArr = 0
For y = i To Counter + i
.Range("A" & y).Value = pokedex_number
.Range("B" & y).Value = name
.Range("C" & y).Value = classfication
.Range("D" & y).Value = varSplit(CounterArr)
CounterArr = CounterArr + 1
Next y
End If
Next i
End With
End Sub
Sub Clean(ByVal str As String)
strResults = Replace(Replace(Replace(Replace(str, "]", ""), "[", ""), " ", ""), "'", "")
End Sub
答案 1 :(得分:0)
使用Power Query
(又名Get&Transform
)将功能列拆分为行
然后删除多余的字符[]'
这一切都可以在PQ GUI中完成。
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Replaced Value" = Table.ReplaceValue(Source,"[","",Replacer.ReplaceText,{"abilities"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","'","",Replacer.ReplaceText,{"abilities"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","]","",Replacer.ReplaceText,{"abilities"}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Replaced Value2", {{"abilities", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "abilities"),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"abilities", type text}})
in
#"Changed Type"