作者:Gemini_2 | 来源:互联网 | 2023-05-18 11:35
Ihavetwocolumnsofnumbers,togethertheywillbeunique(compositekey).Iwouldliketocreate
I have two columns of numbers, together they will be unique (composite key). I would like to create an unique ID number (third column) similar to how MS Access would use a primary key. I would like to do this in VBA but I am stuck on how to do it.
我有两列数字,它们将是唯一的(复合键)。我想创建一个唯一的ID号(第三列),类似于MS Access如何使用主键。我想在VBA中这样做,但我仍然坚持如何做到这一点。
My VBA in excel isn't very good so hopefully you can see what I've started to attempt. it may be completely wrong... I don't know?
我在excel中的VBA不是很好,所以希望你能看到我开始尝试的东西。这可能完全错了......我不知道?
I don't know how to make the next concatenation and I am unsure about how to go down to the next row correctly.
我不知道如何进行下一次连接,我不确定如何正确地进入下一行。
Sub test2()
Dim var As Integer
Dim concat As String
cOncat= Range("E2").Value & Range("F2").Value
var = 1
'make d2 activecell
Range("D2").Select
Do Until cOncat= ""
'if the concat is the same as the row before we give it the same number
If cOncat= concat Then
var = var
Else
var = var + 1
End If
ActiveCell.Value = var
ActiveCell.Offset(0, 1).Select
'make the new concatination of the next row?
Loop
End Sub
any help is appreciated, thanks.
任何帮助表示赞赏,谢谢。
4 个解决方案