有的时候编全桥共数量表,有整体式也有分离式的,编序号就有点麻烦,如果桥多,大批量表格只能手动一个个输,费时又容易出错。
用VBA就简单多了,一键批量生成连续序号,合并单元格、独立单元格通通适配。
Sub MarkSequenceInD() Dim ws As Worksheet Dim startRow As Long, endRow As Long Dim currentRow As Long Dim seq As Long Set ws = ActiveSheet startRow = 6 endRow = 35 currentRow = startRow seq = 1 Do While currentRow <= endRow DoEvents If ws.Cells(currentRow, "D").MergeCells Then ' 合并单元格在首单元格标注序号 Dim mergeRng As Range Set mergeRng = ws.Cells(currentRow, "D").MergeArea mergeRng.Cells(1, 1).Value = seq currentRow = mergeRng.Row + mergeRng.Rows.Count seq = seq + 1 Else ' 独立单元格直接标注序号 ws.Cells(currentRow, "D").Value = seq currentRow = currentRow + 1 seq = seq + 1 End If Loop MsgBox "序号标注完成!"End Sub