VBA逻辑行标题列EXCEL

我遇到了一些VBA代码的逻辑麻烦,因此我不能提供任何代码,因为它缺less太多的部分..基本上我需要做的是改变这样的事情:

A x1 x2 x3 B y1 y2 y3 Into this: A x1 A x2 A x3 A B y1 B y2 B y3 B 

这是一个大的excel文档,所以循环将是必要的! 任何指导当然赞赏:)提前致谢!

怎么样:

 Sub cutaneous() Dim N As Long N = Cells(Rows.Count, "A").End(xlUp).Row For i = 1 To N - 3 Step 4 v = Cells(i, 1).Value Cells(i + 1, 1).Value = Cells(i + 1, 1).Value & " " & v Cells(i + 2, 1).Value = Cells(i + 2, 1).Value & " " & v Cells(i + 3, 1).Value = Cells(i + 3, 1).Value & " " & v Next i End Sub 

这只有在你的标题下总是有3个子项时才有效。 如果你有两个或四个; 这是行不通的。 我会亲自实施一些不同的解决scheme,可能是这样的:

 Sub DistinguishItems() Dim iLastRow, iCounter As Long iLastRow = Cells(Rows.Count, "A").End(xlUp).Row Dim sDistinguisher As String For iCounter = 1 To iLastRow If Len(Range("A" & iCounter)) = 1 Or IsNumeric(Right(Range("A" & iCounter).Value, 1)) = False Then sDistinguisher = Range("A" & iCounter).Value Else Range("B" & iCounter).Value = sDistinguisher End If Next iCounter End Sub