【问题标题】:How to write insert new row after values do not repeat each other VBA code?如何在值不相互重复VBA代码后编写插入新行?
【发布时间】:2016-12-09 08:10:10
【问题描述】:

我有一列数字如下:

66234 
666575 
66567 
665687 
66090 
66000

而且我需要编写检测“77”+ SomeNumber 何时开始的代码。并在新数字之间插入空行。

我应该使用什么命令?

【问题讨论】:

  • Range("").EntireRow.Insert
  • Rows(x).Insert Shift:=xlDown 其中x 是行号。您能否澄清这一行:“检测 77 + SomeNumber 何时开始”
  • 看看stackoverflow.com/questions/15417544/… /// 只用 Left(Cells(iRow + 1, iCol), 2) Left(Cells(iRow, iCol), 2) 代替原来的

标签: vba excel


【解决方案1】:

试试下面的:

Sub InsertRow()

Dim i As Long
Dim n As Long

n = Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To n
    If Left(Cells(i, 1), 2) = 77 Then
        Cells(i + 1, 1).EntireRow.Insert
    End If
Next i

End Sub

n=... 中的 1 替换为包含主要数字的列 用相应的行替换 cells(i,1)for i =1 以开始:)

【讨论】:

  • 这对您有帮助吗?
猜你喜欢
  • 2014-11-07
  • 2019-09-11
  • 1970-01-01
  • 2014-10-25
  • 1970-01-01
  • 1970-01-01
  • 2014-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多