Excel 問題 如何用VBA同时进行几组自动编号問題?

excelVBA

1个回答

写回答

嘉嘉的家家

2025-12-21 18:28

+ 关注

excel
excel

excel中,如果想在B列中显示编号,可以使用VBA宏来实现。下面是一个示例宏的代码:vbnetSub AutoNumber()Dim i As LongDim a As Longa = 1For i = 1 To Range("A2").End(xlDown).RowIf Cells(i, "A") = "A" ThenCells(i, "B") = Str(a) & "1"a = a + 1End IfIf Cells(i, "A") = "B" ThenCells(i, "B") = Str(a) & "2"a = a + 1End IfIf Cells(i, "A") = "C" ThenCells(i, "B") = Str(a) & "3"a = a + 1End IfIf Cells(i, "A") = "D" ThenCells(i, "B") = Str(a) & "4"a = a + 1End IfIf Len(Cells(i, "B")) = 2 ThenCells(i, "B") = Left(Cell

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号