将空行插入列以匹配相邻列中的空行

时间:2015-06-23 01:37:08

标签: excel excel-formula excel-2010 formula

我正在尝试将三个相邻列中的数据与第四列中的数据进行匹配。

这就是我目前的数据组织方式:

ROW   A     B     C
----------------------
1    Cat   Car    Red
2    Dog   Bike   Blue
3    Bird  Car    
4    Bear  Car    Blue
5    Fish  Bike   Red  
6    Cow   Car    Red 

(A列中的值是唯一的; B和C中的值是重复值)

这就是我需要组织的方式:

ROW   A     B     C
----------------------
1    Cat   Car    Red
2    Dog   Bike   Blue
3
4    Bird  Car    Blue
5    Bear  Car    Red
6    Fish  Bike   Red

基本上,我需要列A和B来查看第3行中的列C是空的,并在A3和B3中插入空白单元格,以便下面的每个A和B值向下移动一个。

电子表格包含许多必需的插入内容。其中一些将是单独插入,如上例所示,但其他插入可能连续插入3个,4个,5个,10个。

我可以使用某种公式或某种自动化流程来实现这一目标吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

从您发布的示例中,您想在C为空白时按下A和B?

Sub PushDown()
    Dim X As Long
    For X = 1 To Range("A" & Rows.Count).End(xlUp).Row
        If IsEmpty(Range("C" & X)) Then Range("A" & X & ":B" & X).Insert xlDown
    Next
End Sub

答案 1 :(得分:0)

Sub clearContent()
Dim lastrow As Integer

lastrow = Range("D65536").End(xlUp).Row

For i = 2 To lastrow
    If Cells(i, 4) = "" Then
        Range(Cells(i, 2), Cells(i, 3)).ClearContents
    End If
Next i
End Sub
相关问题