创建两边具有相同字母的序列号
Creating Sequence numbers with same letters eitherside
如何在两边都有字母的列表末尾创建序号,它总是 MW....A,所以改变中间的数字?这可以使用一个按钮来完成,所以当点击这些按钮时,它们会在列表的底部创建。
谢谢
请试试这个代码:
它会将 maxInc
个单位添加到现有的 startNo
值,范围从 lastRow
行开始...
Sub testIncrementValString()
Dim sh As Worksheet, i As Long, lastRow As Long, startNo As Long, maxInc As Long
Set sh = ActiveSheet 'use here your sheet
maxInc = 10: startNo = 1670: lastRow = 155
For i = 1 To maxInc
sh.Range("A" & lastRow + i).Value = "MW" & startNo + i & "A"
Next i
End Sub
可以调整代码以找到字符串中的最后一个数字,A:A 列的最后填充行并添加一个单位,或者您需要多少个用于以下...
像这样:
Sub testIncrementValString_bis()
Dim sh As Worksheet, i As Long, lastRow As Long, startNo As Long, maxInc As Long
Set sh = ActiveSheet 'use here your sheet
lastRow = sh.Range("A" & sh.Rows.count).End(xlUp).Row
startNo = CLng(Mid(sh.Range("A" & lastRow).Value, 3, _
Len(sh.Range("A" & lastRow).Value) - 3))
maxInc = 10
For i = 1 To maxInc
sh.Range("A" & lastRow + i).Value = "MW" & startNo + i & "A"
Next i
End Sub
如何在两边都有字母的列表末尾创建序号,它总是 MW....A,所以改变中间的数字?这可以使用一个按钮来完成,所以当点击这些按钮时,它们会在列表的底部创建。 谢谢
请试试这个代码:
它会将 maxInc
个单位添加到现有的 startNo
值,范围从 lastRow
行开始...
Sub testIncrementValString()
Dim sh As Worksheet, i As Long, lastRow As Long, startNo As Long, maxInc As Long
Set sh = ActiveSheet 'use here your sheet
maxInc = 10: startNo = 1670: lastRow = 155
For i = 1 To maxInc
sh.Range("A" & lastRow + i).Value = "MW" & startNo + i & "A"
Next i
End Sub
可以调整代码以找到字符串中的最后一个数字,A:A 列的最后填充行并添加一个单位,或者您需要多少个用于以下...
像这样:
Sub testIncrementValString_bis()
Dim sh As Worksheet, i As Long, lastRow As Long, startNo As Long, maxInc As Long
Set sh = ActiveSheet 'use here your sheet
lastRow = sh.Range("A" & sh.Rows.count).End(xlUp).Row
startNo = CLng(Mid(sh.Range("A" & lastRow).Value, 3, _
Len(sh.Range("A" & lastRow).Value) - 3))
maxInc = 10
For i = 1 To maxInc
sh.Range("A" & lastRow + i).Value = "MW" & startNo + i & "A"
Next i
End Sub