Excel insert row marco

2013-09-28 1:42 am
我個excel column A, 如果有個n 字, 就不插入新行, 如有其他字, 就插入一行.

如:
cell A1 = n
cell A2 = 9
cell A3 = n
cell A4 = bb
.
.
.
cell A100 = n

我想在 cell A2 & A4底下(所有卝"n") 自動加一行. 可以嗎?

回答 (1)

2013-09-28 6:39 pm
✔ 最佳答案
若出現 n 字就在下一ROW插入一空行,marco如下:
Sub addrow()
For X = 1 To 100 * 2
If Cells(X, 1) = "n" Then Rows(X + 1).Insert Shift:=xlDown
Next X
End Sub

若出現含 n 字 (如: no, on, non...) 就在下一ROW插入一空行,marco如下:
Sub addrow()
For X = 1 To 100 * 2
If Cells(X, 1) Like "*n*" Then Rows(X + 1).Insert Shift:=xlDown
Next X
End Sub

2013-09-28 11:09:17 補充:
Sorry, 睇錯問題,我以為是有n就 "插入" ,應為"不插入",marco如下:

Sub addrowA()
R = 1
For X = 1 To 100
If Cells(R, 1) = "n" Then
R = R + 1
Else
Rows(R + 1).Insert Shift:=xlDown
R = R + 2
End If
Next X
End Sub


收錄日期: 2021-04-13 19:44:14
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20130927000051KK00147

檢視 Wayback Machine 備份