Excel中用VBA,按顺序添加序号?

Excel中用VBA,按顺序添加序号?,第1张

简单的说就是 点 大项,在A列非空,依次写A或B。。。C...D

小项 就是 数字 递增,根据前面的

A列先输入 A

Sub 大项()

Dim i

For i = Range("A65536").End(xlUp).Row To 1 Step -1

x = Asc(Cells(i, 1))

If (x >= 65 And x <= 90) Then

n = Range("A65536").End(xlUp).Row

Cells(n + 1, "A") = Chr(1 + x)

Exit Sub

End If

Next

End Sub

Sub 小项()

Dim n

n = Range("A65536").End(xlUp).Row

x = Asc(Cells(n, 1))

If (x >= 65 And x <= 90) Then

Cells(n + 1, "A") = 1

Else

Cells(n + 1, 1) = Cells(n, 1) + 1

End If

End Sub

For x= Cells(65536,2).End(xlup).Row to 2

If Cells(x,2)=Cells(x+1,2) Then

Cells(x+1,3)=cells(x,3)+Cells(x+1,3)

Cells(x,2).EntireRow.Delete

end if

next

亲,一定要用VBA吗?

代码如下。

打开你的Excel文件,按“Alt+F11”打开VBA编辑窗口,然后在左侧对应的Sheet上双击,右侧空白处粘贴下面的代码。关闭VBA窗口。然后按“Alt+F8”打开宏窗口,选择刚插入的宏,点击“执行”。

Sub xm()

Dim n, i, r As Long

r = UsedRange.SpecialCells(xlCellTypeLastCell).Row

Dim s As String

For i = 2 To r

    If Range("B" & i).Value <> "" Then s = Range("B" & i).Value: n = 1

    Range("C" & i).Value = s & n: n = n + 1

Next

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11603297.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存