添加标题
Sub IterateCells1()
Dim rng As Range
Dim cell As Range
Dim currentRow As Long
' 设置要遍历的范围
Set rng = ThisWorkbook.Sheets("Sheet2").Range("A1:A16768")
Set rng1 = ThisWorkbook.Sheets("Sheet1").Range("A1:A16768")
'添加行
For r = rng.Count To 1 Step -1
If rng(r).Value = "1" Then
rng(r).EntireRow.Insert
Debug.Print r
End If
Next r
'在添加的行里赋值
For r = rng.Count To 1 Step -1
If rng(r).Value = "" Then
rng.Cells(r, "A").Value = "序号"
rng.Cells(r, "B").Value = "列名"
rng.Cells(r, "C").Value = "数据类型"
rng.Cells(r, "D").Value = "长度"
rng.Cells(r, "E").Value = "小数位"
rng.Cells(r, "F").Value = "主键"
rng.Cells(r, "G").Value = "允许空"
rng.Cells(r, "H").Value = "默认值"
rng.Cells(r, "I").Value = "列说明"
Debug.Print r
End If
Next r
'再一次添加行
For r = rng.Count To 1 Step -1
If rng(r).Value = "序号" Then
rng(r).EntireRow.Insert
End If
Next r
'在添加行里赋值 合并单元格
For r = rng.Count To 1 Step -1
If rng(r).Value = "" Then
rng.Cells(r, "A").Value = rng1.Cells(r + 1, "A").Value & " " & rng1.Cells(r + 1, "B").Value
ThisWorkbook.Sheets("Sheet2").Range("A" & r + 1 & ":I" & r + 1).Merge
Debug.Print r
End If
Next r
End Sub