更改VBA宏代码以更改编号 [英] Changing VBA macro code to change number
本文介绍了更改VBA宏代码以更改编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做的是递增数字,然后循环用 1
减去前两个 2
数字然后增加其余部分,直到第一个 2
位数字= 0
What I'm trying to do is increment number and then loop subtract the first 2
digits by 1
and then increment the rest until the first 2
digits = 0
所以我有 M201001
会变成 m191002
,下一个会是 m181003
,直到 m011020
So I have M201001
would become m191002
and next would be m181003
until m011020
推荐答案
您需要做的是使用 left
, mid
和 right
函数.
What you'll need to do is break up your value into 3 using left
, mid
and right
functions.
然后根据需要执行循环.我正在自己尝试一下,因此一旦完成,我将更新我的答案.
Then do the looping as you require it. I'm trying it out myself so I'll update my answer once I've done so.
添加的代码:
Sub Testing()
Dim myIn As String
myIn = "M201001"
Dim myLeft As String
Dim myMid As Integer, myRight As Integer, i As Integer
Dim myOut As String
myLeft = Left(myIn, 1)
myMid = CInt(Mid(myIn, 2, 2))
myRight = CInt(Right(myIn, 4))
myOut = myLeft & Format(myMid, "00") & Format(myRight, "0000")
i = 0
Debug.Print "IN: " & myIn
Debug.Print "BROKEN UP: " & myOut
Do Until myMid = -1
Debug.Print "ITERATION " & Format(i, "00") & ": " & myLeft & Format(myMid, "00") & Format(myRight, "0000")
myMid = myMid - 1
myRight = myRight + 1
myOut = myLeft & Format(myMid, "00") & Format(myRight, "0000")
i = i + 1
Loop
End Sub
如果您需要任何解释,请询问.我很乐意解释.
If you need any explanation please ask. I will be happy to explain.
这篇关于更改VBA宏代码以更改编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文