我正在尝试使用VBA生成采购订单编号。该数字基于日期加上" -1或2或3或4等等"确保在同一天生成的多个采购订单没有重复项。我已经达到了用#" -1"生成PO的程度。最后,认识到PO已存在于我的范围内并产生一个新的PO,其中包含" -2"在末尾。但是,我无法生成大于" -2"的PO。这是我的代码:
Set ws2 = Worksheets("Data Sheet")
Dim ponum As String
Dim podate As String
Dim n As Integer
ws2.Activate
ActiveSheet.Unprotect "1896"
podate = Format(Now(), "yyyymmdd")
n = 1
ponum = podate & "-" & n
Set Rng = Worksheets("Data Sheet").Range("A1:A100000")
For Each c In Rng.Cells
If c.Value <> "" And c.Value = ponum Then
n = n + 1
ponum = podate & "-" & n
End If
Next c