简体   繁体   English

Excel-VBA-范围选择会降低PC速度

[英]Excel - VBA - Range Selection Slows Down PC

Is there a way to turn these commands into one? 有没有办法将这些命令变成一个?

Worksheets("Agent html").Select
Range(Cells(7, TotalCallsRow), Cells(lastrow, TotalCallsRow)).Copy

When i give: 当我给:

Worksheets("Agent html").Range(Cells(7, TotalCallsRow), Cells(lastrow, TotalCallsRow)).Copy

It returns me error 它返回我错误

Application Defined or object-defined error. 应用程序定义或对象定义的错误。

Thanks in advance. 提前致谢。

It should be: 它应该是:

Worksheets("Agent html").Range(Worksheets("Agent html").Cells(7, TotalCallsRow), Worksheets("Agent html").Cells(lastrow, TotalCallsRow)).Copy

It may be cleaner to define the worksheet as an object variable like: 将工作表定义为对象变量可能更简洁:

Dim ws As Worksheet
Set ws = Worksheets("Agent html")

ws.Range(ws.Cells(7, TotalCallsRow), ws.Cells(lastrow, TotalCallsRow)).Copy

You are using Cells within Range , I'm not sure that's allowed. 您正在使用Range内的Cells ,但不确定是否允许。 Either way, try to not use .Select 无论哪种方式,请尝试不使用.Select

Dim wksht As Worksheet
Set wksht = Worksheets("Agent html")
Dim rng As Range
rng = wksht.Range(Cells(7, TotalCallsRow), Cells(lastrow, TotalCallsRow))
rng.Copy

Will do what you are asking above without selecting anything. 无需选择任何内容,即可完成您上面的要求。 I've not tested the Range(Cells but I can't help with that as I don't know what TotalCallsRow is? 我尚未测试Range(Cells但我对此无能为力,因为我不知道什么是TotalCallsRow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM