我有以下问题,我有2列,如下所示:
A B
"X" 1
"Y" 1
"Z" 0
"W" 2
我想做的是找到一种创建新列C和D或更好的方法,如下更新列A和B:
C D
"X" 1
"Y" 1
"Z" 0
"W (1)" 1
"W (2)" 1
任何有关如何执行此操作的建议或想法,将不胜感激。
答案 0 :(得分:0)
这不应该是代码编写论坛。您将需要付出一些努力。
Sub split_()
Dim P1 As Range
Range("C1:D99999").Clear
Set P1 = Range("A1").CurrentRegion
a = 1
For i = P1(1).Row To P1.Rows.Count
If P1(i, 2) > 1 Then
For j = 1 To P1(i, 2)
Cells(a, 3) = P1(i, 1) & " (" & j & ")"
Cells(a, 4) = 1
a = a + 1
Next j
Else
Cells(a, 3) = P1(i, 1)
Cells(a, 4) = P1(i, 2)
a = a + 1
End If
Next i
End Sub