[英]VBA Copy & pasting adjacent columns of multiple rows
I wrote a simple macro to Copy and paste one row of two adjacent columns,I then added the app.ontime to automatically run the copy&paste macro. 我编写了一个简单的宏来复制并粘贴两个相邻列的一行,然后添加了app.ontime以自动运行复制粘贴宏。 I have multiple rows of data I want to apply my macro to.
我想将宏应用于多行数据。 Any thoughts?
有什么想法吗?
Public Sub PasteDynamicData()
'runs TestKDdata every Xmin
Sheets("MOVINGAVGDATAFromKD").Range("C4").Copy
Range("J4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("MOVINGAVGDATAFromKD").Range("I4:j4").Insert _
shift:=xlDown
Sheets("MOVINGAVGDATAFromKD").Range("D4").Copy
Range("m4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Sheets("MOVINGAVGDATAFromKD").Range("L4:M4").Insert _
shift:=xlDown
Sheets("MOVINGAVGDATAFromKD").Range("i87:m87").ClearContents
End Sub
Public Sub UpdateDataClock()
'Clock that prompts running of PasteDynamicData
Sheets("MOVINGAVGDATAFromKD").Select
Call PasteDynamicData
Nexttick = Now + TimeValue("00:00:30")
Application.OnTime Nexttick, "updatedataclock"
If Time >= TimeValue("16:00:00") Then
Application.OnTime Nexttick, "updatedataclock", , False
End If
End Sub
(I declared "nexttick as date" in the module).
Could you explain what exactly the problem is? 您能解释一下到底是什么问题吗? What do you want fixed or improved?
您想要解决或改进什么? Is something not working?
有事吗?
Anyway, try the following: 无论如何,请尝试以下操作:
Public Sub PasteDynamicData()
Dim xlMovingSheet As Worksheet
Set xlMovingSheet = ActiveWorkbook.Worksheets("MOVINGAVGDATAFromKD")
xlMovingSheet.Range("C4").Copy
xlMovingSheet.Range("J4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
xlMovingSheet.Range("I4:j4").Insert _
shift:=xlDown
xlMovingSheet.Range("D4").Copy
xlMovingSheet.Range("m4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
xlMovingSheet.Range("L4:M4").Insert _
shift:=xlDown
xlMovingSheet.Range("i87:m87").ClearContents
Call UpdateDataClock
End Sub
For the update section, set whatever time increment that you'd like. 对于更新部分,设置您想要的任何时间增量。 Right now it is set to run PasteDynamicData every 30 seconds.
现在设置为每30秒运行一次PasteDynamicData。
Public Sub UpdateDataClock()
Application.OnTime Now() + TimeValue("00:00:30"), "PasteDynamicData"
If Time >= TimeValue("16:00:00") Then
Application.OnTime EarliestTime:=Now() + TimeValue("00:00:30"), Procedure:="PasteDynamicData", Schedule:=False
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.