在Excel中创build额外的行

我如何添加新行:

Column A Column B Column C 11 Size S 11 Color Yellow 11 Type Q 22 Size M 22 Color Blue 22 Type W 33 Size L 33 Color Brown 33 Type R 

这在Excel中: –

 Column A Column B Column C 11 Size S 11 Color Yellow 11 Type Q 11 Model T1 11 Grade 1 11 LotNo Z10 22 Size M 22 Color Blue 22 Type W 22 Model T2 22 Grade 1 22 LotNo M10 33 Size L 33 Color Brown 33 Type R 33 Model T3 33 Grade 2 33 LotNo C10 

谢谢,

短发

假设你的意思是在VBA中这样做(因为它是标记的macros ,这是一个编程问答网站),你可以插入和填充一行代码:

 Range("A3").EntireRow.Insert Range("A3").Formula = "=11" Range("B3").Value = "Hello" 

其他的一切都只是找出一个能完成整个事情的循环。 下面的代码将根据您的需要扩展行(通过在每个Type行之后添加ModelGradeLotNo行)。 这些项目的实际值保留为?? 因为不清楚如何从其他数据计算它们。

 Sub Macro1() Dim Row As Integer Row = 1 While Range("B" & Row).Value <> "" Row = Row + 1 Wend While Row <> 1 If Range("B" & (Row - 1)).Value = "Type" Then Range("A" & Row).EntireRow.Insert Range("A" & Row).Formula = Range("A" & (Row - 1)).Formula Range("B" & Row).Value = "LotNo" Range("C" & Row).Value = "??" Range("A" & Row).EntireRow.Insert Range("A" & Row).Formula = Range("A" & (Row - 1)).Formula Range("B" & Row).Value = "Grade" Range("C" & Row).Value = "??" Range("A" & Row).EntireRow.Insert Range("A" & Row).Formula = Range("A" & (Row - 1)).Formula Range("B" & Row).Value = "Model" Range("C" & Row).Value = "??" End If Row = Row - 1 Wend End Sub