我只是在范围内的单元格为空时才尝试添加唯一ID。这样它将保留旧ID,但会为新行创建唯一ID。对于下面的代码,我尝试使用数字14(2014年)创建和ID,并在我的数据集中使用另外两个数字变量(ADPNumber和PRJNumber)。然后id将变化整数“i”,其必须是4位数。我在下面的代码“Set myCell ...”
的行中得到运行时错误13 For Each myCell In ActiveSheet.Range("a9:a89").Cells
Dim i
i = 1
'i.NumberFormat = "0000"
If myCell.Value = "" Then
Set myCell = "14" & ADPNumber & PRJNumber & Format(i, "0000")
i = i + 1
End If
Next myCell
答案 0 :(得分:1)
尝试:
myCell.Value = "14" & ADPNumber & PRJNumber & Format(i, "0000")