首页 \ 问答 \ 如何更快地为此VBA循环(对于每个单元格,复制粘贴)?(How can I make this VBA loop (for each cell, copy paste) faster?)

如何更快地为此VBA循环(对于每个单元格,复制粘贴)?(How can I make this VBA loop (for each cell, copy paste) faster?)

我有一段代码占用了大量的实际运行时间。 似乎这个循环实际上使Excel有时没有响应(不是100%肯定这一点,但在我看来,这是我最有可能的罪魁祸首)。 无论如何,我想优化这段代码,所以它不需要这么长时间。

一些背景:

编辑: application.screenupdating设置为false
表格(1)= RawData
表(2)= AreaTable
在进入循环之前j = 2
rng是包括sheet1列CJ中所有值减去标题的范围

在sheet1列中,CJ是我想循环的ComponentNames列表。 对于每个ComponentName,我想过滤列AL并复制粘贴(转置)列AL中的所有可见值(总是至少> 1值)到Sheets(2)。

对于每个ComponentName,通常有大约1000-1200个ComponentNames和10-240个值(与我复制粘贴到sheet2的值相同)。

For Each cell In rng
    ComponentName = cell.Value
    RawData.Range("A:CJ").AutoFilter field:=17, Criteria1:=ComponentName
    RawData.Range("AL2", Range("AL2").End(xlDown)).Cells.SpecialCells(xlCellTypeVisible).Copy
    AreaTable.Range("B" & j).PasteSpecial Transpose:=True
    j = j + 1
Next cell

我可以对此循环进行哪些更改以更快地完成此过程?


I have a piece of code that is taking up a large amount of the actual runtime. It seems like this loop actually makes Excel unresponsive at times (not 100% sure about this, but this seems to me the most likely culprit when I stepped through the code). Anyways, I want to optimize this piece of code so it doesn't take so long.

Some background:

EDIT: application.screenupdating is set to false
Sheets(1) = RawData
Sheets(2) = AreaTable
j=2 before entering the loop
rng is the range including all values in sheet1 column CJ minus the header

In sheet1 column CJ is a list of ComponentNames that I want to loop through. For each ComponentName, I want to filter column AL and copy paste (transpose) all the visible values in column AL (there will always be at least >1 value) to Sheets(2).

There are usually around 1000-1200 ComponentNames and anywhere from 10-240 values (the same values that I'm copy pasting to sheet2) for each ComponentName.

For Each cell In rng
    ComponentName = cell.Value
    RawData.Range("A:CJ").AutoFilter field:=17, Criteria1:=ComponentName
    RawData.Range("AL2", Range("AL2").End(xlDown)).Cells.SpecialCells(xlCellTypeVisible).Copy
    AreaTable.Range("B" & j).PasteSpecial Transpose:=True
    j = j + 1
Next cell

What changes can I make to this loop to get the process done faster?


原文:https://stackoverflow.com/questions/34024861
更新时间:2022-12-12 18:12

最满意答案

来自Github API参考上市组织

注意:分页仅由since参数提供。 使用链接标头获取下一页组织的URL。

例如,使用curl检查第二页:

curl -I "https://api.github.com/organizations"

给出以下链接头:

Link: <https://api.github.com/organizations?since=3043>; rel="next", <https://api.github.com/organizations{?since}>; rel="first"

所以下一页将是https://api.github.com/organizations?since=3043

对于每个请求,您将检查此标头以获取要触及的下一个URL


From Github API reference for listing organizations :

Note: Pagination is powered exclusively by the since parameter. Use the Link header to get the URL for the next page of organizations.

For instance checking the 2nd page using :

curl -I "https://api.github.com/organizations"

gives the following link header :

Link: <https://api.github.com/organizations?since=3043>; rel="next", <https://api.github.com/organizations{?since}>; rel="first"

So the next page will be https://api.github.com/organizations?since=3043

For each request you would check this header to get the next url to hit

相关问答

更多
  • 这是OAuth的本质。 您可以尝试使用基本身份验证方法 ,但如果这不符合您的需求,那么PHP有一个OAuth库 ,可以使身份验证非常轻松。 还有一些用于Github API的PHP包装器,例如php-github-api 。 This is the nature of OAuth. You could you try to use the basic authentication method, but if that doesn't fit your needs, then PHP has an OAut ...
  • 来自Github API参考上市组织 : 注意:分页仅由since参数提供。 使用链接标头获取下一页组织的URL。 例如,使用curl检查第二页: curl -I "https://api.github.com/organizations" 给出以下链接头: Link: ; rel="next", ; rel="fir ...
  • 为了让shortlisthome分叉存储库,您需要对它们进行身份验证。 您尝试分叉的存储库是公共的 ,因此您需要做的就是为shortlisthome获取OAuth令牌,然后向您现在制作的那个发出类似的请求。 唯一的区别是您不需要提供{"organization": "shortlisthome"}的JSON主体。 对于它的价值,当您是具有适当权限的组织的成员并且您希望将存储库分叉到该组织时,可选的JSON主体供您使用。 除非您经过身份验证,否则无法将存储库分叉到其他人的帐户。 In order for sh ...
  • 两个选项。 一个只是解码它: require 'base64' plaintext = Base64.decode64(data['content']) 或者,您可以在其API上使用原始内容请求。 将此添加到您的标题中: Accept: application/vnd.github.VERSION.raw 用您的API版本替换VERSION。 Two options. One is just to decode it: require 'base64' plaintext = Base64.decode ...
  • 我将问题提交给了Github API的支持,他们给了我一个非常详细的答案。 这是(缩短): 看起来您的遗失提交是使用未与您的GitHub个人资料相关联的电子邮件地址创作的。 您可以通过在提交URL的末尾添加“.patch”找到丢失的电子邮件,然后查看“发件人:”行。 收到电子邮件后,您可以按照以下说明将其链接到您的个人资料: https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user 将电子邮件关联到您的帐户后,任 ...
  • 你混淆了两个不同的东西,passport-github支持OAuth 2,这是OAuth协议的版本,而Github API是版本3。 使用passport-github,您可以使用scope和state如下: app.get('/auth/github', passport.authenticate('github', { scope: ['user', 'repo'], state: 'foobar' })); You are confusing two different things, pa ...
  • 目前,Search API仍在GitHub Enterprise上进行预览。 因此,您需要在Accept标头中指定一种特殊的媒体类型才能使其正常工作。 尝试一下: curl -i -H "Accept: application/vnd.github.preview+json" -H "Authorization: token " https://github.mycompany.com/api/v3/search/code?q=class Currently, the Search API i ...
  • DELETE方法现在在这里: http : //developer.github.com/v3/repos/#delete-a-repository The DELETE method is now here: http://developer.github.com/v3/repos/#delete-a-repository
  • GitHub将其专有的Releases功能与常规Git标签混合在一起。 您在ffmpeg中看到的许多“版本”实际上只是标签。 这是一个真实版本的示例 。 请注意它如何包含比标记更多的信息。 尽管他们的Web UI显示标签与版本混合,但GitHub的发布API端点不包含常规标签 : 这将返回一个版本列表,其中不包含尚未与版本关联的常规Git标记。 要获取Git标记列表,请使用Repository Tags API 。 使用标签端点作为GitHub建议提供更多结果,并包含您期望的Link头: curl -is ...
  • GitHub API 声明 : 默认情况下,返回多个项目的请求将分页为30个项目。 您可以使用?page参数指定更多页面。 The GitHub API states: Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)