我目前在下面附加了代码。当我在Sheet2上放置一个按钮(带有VBA代码)并运行它时,它可以工作。但是,我希望将按钮放在Sheet1上,但同时要在Sheet2上进行更改。
Sub SaveData()
Application.ScreenUpdating = False
Dim Rng As Range
For Each Rng In Range("J8:AS78")
If Rng.Value > 0 Then
Rng.Value = Rng.Value
End If
Next Rng
Application.ScreenUpdating = False
End Sub
请帮助我修复此代码。预先感谢。
答案 0 :(得分:1)
您需要指定要处理的图纸。 Range("J8:AS78")
指向当前活动的工作表
尝试
Option Explicit
Sub SaveData()
Application.ScreenUpdating = False
Dim Rng As Range
Dim Ws as worksheet
' change to "sheet2" or whatever name your second sheet has.
Set Ws = Thisworkbook.Sheets("Your sheet name")
With Ws
For Each Rng In .Range("J8:AS78")
If Rng.Value > 0 Then
Rng.Value = Rng.Value
End If
Next Rng
End with
Application.ScreenUpdating = True
End Sub
答案 1 :(得分:0)
添加该范围应应用于哪个工作表。假设它是同一本工作簿。
Option Explicit