format(expression,"格式") format函数(需要转化的表达式,需要转化后的形式)如format(now,"yyyymmdd-hhmmss")将时间转化为年月日-时分秒的格式,又如format(1,"-000")
将数字转化为-001的格式
inputbox(“请输入内容”,消息框)
Sub a()
Dim rng As RangeDim str As String
Set rng = Worksheets("baocun").Cells(Rows.Count, "a").End(xlUp) ' 让rng定位到最后一个
str = Left(rng.Value, 1) ' 让str定位到rng的组名 从而获取在a列中最后一个单元格的组名,并赋值给str字符串变量
[a2].Value = InputBox("qingshuru") ' 输入组名,并赋给a2单元格
If str = [a2].Value Then
[b2] = str & Format(Right(rng, 3) + 1, "-000")‘ 如果字符串变量和我们输入的组名相同,则给小分队起名为组名-00X(+1)’
Else
[b2] = [a2].Value & Format(1, "-000") 如果字符串变量和输入的组名不同,则小分队自动起名为 组名-001 ‘’
End If
[b2].Copy Worksheets("baocun").Cells(Rows.Count, "a").End(xlUp).Offset(1, 0)‘’ 将新组名拷贝到判断区
End Sub