我有两列'Sample_No‘和'Result_Name’。根据不同的结果名称,我希望在'Sample_No‘列中生成一个字母数字字符串NL-#。
例如。
Sample_No(To be generated) Result_Name
NL-1 ABC
NL-2 ABC
NL-3 ABC
NL-1 XYZ
NL-2 XYZ
NL-1 PQR
NL-4 ABC
NL-5 ABC这能在Excel_VBA中完成吗?请帮帮我!任何帮助都将不胜感激!我试着找了几个解决方案,但什么都找不到。
谢谢!
发布于 2019-10-11 20:16:35
您可以按照BigBen的建议通过公式或使用VBA函数"Countif“来完成这一任务。
我假设数据如下所示:

VBA代码:
Sub GenerateAlphaNumber()
Dim lrow As Long
lrow = Cells(Rows.Count, "B").End(xlUp).Row 'find the lastrow in column B
For i = 2 To lrow 'Loop from row 2 until last row
'Check that cell in column B is not empty. If thats' true, then perform countif
If Cells(i, "B").Value <> "" Then Cells(i, 1).Value = "NL-" & WorksheetFunction.CountIf(Range(Cells(2, "B"), Cells(i, "B")), Cells(i, "B").Value)
Next i
End Subhttps://stackoverflow.com/questions/58347723
复制相似问题