我找到了以下代码:
Sub InsertMissingDates()
Dim i As Long
Dim RowCount As Long
i = 4
Do
If Cells(i, 1) + 1 < Cells(i + 1, 1) Then
Rows(i + 1).Insert
Cells(i + 1, 1) = Cells(i, 1) + 1
End If
If (Cells(i + 1, 1) = "") Then
Cells(i + 1, 1) = Cells(i, 1) + 1
End If
i = i + 1
Loop Until Cells(i, 1).Value >= DateSerial(2016, 1, 30)
End Sub
我如何指向E列而不是A列?
答案 0 :(得分:1)
您需要在Cells函数上更改参数
https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet.cells
“在单元格上”起作用第二个参数:
1- A
2- B
3- C
4- D
5- E
因此,如果您更改代码并使用5而不是1,它将在单元格E上工作
Sub InsertMissingDates()
Dim i As Long
Dim RowCount As Long
i = 4
Do
If Cells(i, 5) + 1 < Cells(i + 1, 5) Then
Rows(i + 1).Insert
Cells(i + 1, 5) = Cells(i, 5) + 1
End If
If (Cells(i + 1, 5) = "") Then
Cells(i + 1, 5) = Cells(i, 5) + 1
End If
i = i + 1
Loop Until Cells(i, 5).Value >= DateSerial(2016, 1, 30)
End Sub
答案 1 :(得分:0)
使用参数确定列:
/usr/bin/[ --help