excel - How to paste values across multiple worksheets in Excel VBA
问题描述
Could anyone share knowledge about how to paste values from one worksheet to multiple worksheets, starting from a specific column?
I want to copy formulas from the worksheet ("Template") and paste it to other worksheets starting from the column F1 all the way to the last column/row. Following is my codes. I was stuck from Line 5 and can't figure a way to paste values without looking at the names of the sheets. Could anyone advise how to solve this challenge? Thank you :)
Dim Y as workbook
Set Y = Thisworkbook
Dim copydata as Long
copydata=y.worksheets("Template").UsedRange.Rows.Count
Dim i as Long
For i=3 to sheets.count
Y.worksheets("name").Range("F1:x"©data).Formula= _
Y.worksheets("Template").Range("F1:X"©data).Formula
解决方案
Here's the code from my comment above. Suggestion is to switch to a For Each
loop to iterate through all of the worksheets in your workbook. You can employ an If
block to test and skip any sheet where you don't want to copy this formula ("Template" would be the one I know for a fact you should skip).
Dim Y as workbook
Set Y = Thisworkbook
Dim copydata as Long
copydata=y.worksheets("Template").UsedRange.Rows.Count
Dim ws As Worksheet
For Each ws in Y.Worksheets
If ws.Name <> "Template" Then ws.Range("F1:x"©data).Formula = _
y.worksheets("Template").Range("F1:X"©data).Formula
Next ws
推荐阅读
- flutter - 如何在不放大的情况下将视频存储在 S3 存储桶上?
- python-3.x - 在硒中打印网页
- ios - Swift AVPlayer 暂停并转到后台
- typescript - Typeorm 如何在 findOne() 中使用关系
- validation - 验证输入以检测 MongoDB 中的恶意值
- insight.database - 如何使用 Insight 数据库为属性指定用户定义的表类型
- qt - “打开文件”和“创建新文档”的单个对话框
- python-3.x - 从底部开始的第一个最长零子序列之后的子数据帧
- c - 为什么我可以在没有 sigfault 的情况下填充缓冲区?
- javascript - Chrome扩展警报/间隔一段时间后工作