所以我的代码只是分别用“0”和“1”自动填充列“H”和“I”。它可以正常工作,但由于某种原因,当它到达某个部分时,它会变成日期(例如“1/0/1900”,“1/1/1900”。不知道为什么它只会这样做某些细胞而不是其他细胞。这是我的代码:
Sub company()
With Sheets("Combined")
.Columns("A:XFD").NumberFormat = "Number"
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("H2:H" & LastRow).Value = 0
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("I2:I" & LastRow).Value = 1
LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
.Range("A2:A" & LastRow).Value2 = "P"
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("C2:C" & LastRow).Value2 = 7
Sheets("Combined").Select
End With
End Sub
您可以在列中应用数字格式,以确保数字的正确外观,例如
Columns("H:I").NumberFormat = "0"