需要重复30次代码 [英] Need to repeat code 30 times

查看:106
本文介绍了需要重复30次代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我想重新执行它,以便下一列具有与之重复的完全相同的代码。也就是说, D:28 移动到 E:28 和范围 E:110:I120 移动到 F110:J120 。我无法找到一个这样做的循环,任何人都可以帮忙。我的代码是

this is my code and I want to re-execute it so that the next column has the exact same code repeated on it. That is, D:28 moves to E:28 and range E:110:I120 moves to F110:J120. I am having trouble finding a loop that does this, can anyone please help. My code is,

Sub Rebuild() 
tonnes = Range("D28").Value
If tonnes > 2600000 Then

Range("E110:I120").Select
Selection.Copy

Range("E18:I28").Select
ActiveSheet.Paste

Else:

Range("E18:I28").Interior.Color = xlNone
Range("E18:I18") = ""
Range("E19:I19") = ""
Range("E20:I20") = 0
Range("E21:I21") = 2.4
Range("E22:I22") = "=E21+E20"
Range("E23:I23") = "=24 - E22"
Range("E24:I24") = "=100 * E23 / 24"
Range("E25:I25") = 3000
Range("E26:I26") = "=E25 * E23"
Range("E27:I27") = "=E26"
Range("E28:I28") = "=D28 + 27"

End If
End Sub


推荐答案

Option Explicit

Sub Rebuild()

Dim cumtonnes As Long

'you initially had tonnes as the variable name, but I was not sure if this was a typo or not.
cumtonnes = Range("D28").Value

If cumtonnes > 2600000 Then

    Range("E110:I120").Copy Range("F110:J120")

    Range("D28").Copy Range("E28")

Else:

    Range("E18:I28").Interior.Color = xlNone
    Range("E18:I18") = ""
    Range("E19:I19") = ""
    Range("E20:I20") = 0
    Range("E21:I21") = 2.4
    Range("E22:I22") = "=E21+E20"
    Range("E23:I23") = "=24 - E22"
    Range("E24:I24") = "=100 * E23 / 24"
    Range("E25:I25") = 3000
    Range("E26:I26") = "=E25 * E23"
    Range("E27:I27") = "=E26"
    Range("E28:I28") = "=D28 + 27"

End If
End Sub

所以我调整了将复制和粘贴单元格的部分。我目前没有添加任何循环,因为我不知道你想要重复30次。

So I adjusted the part that will do the copy and paste of the cells. I did not add in any loop currently as I did not know what you wanted repeated 30 times.

这篇关于需要重复30次代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆