excel - 将数据从多张纸复制到一张纸中
问题描述
我正在尝试将特定单元格(I106 到 I160)从多张纸复制到第一张纸中。每个都应在新列中彼此相邻复制。但是,它将数据复制到彼此下方的 1 列中。
提前致谢
Sub CopyIt()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If ws.name <> "All Data" Then
ws.Range("I106:I160").Copy
Sheets("All Data").Cells(Rows.Count, "B").End(xlUp).Offset(1).PasteSpecial xlPasteValues
End If
Next
Application.ScreenUpdating = True
End Sub
解决方案
尝试这个:
Sub CopyIt()
Dim ws As Worksheet, c As Range, wsData As Worksheet, wb As WorkBook
Set wb = ActiveWorkbook
Set wsData = wb.Sheets("All Data")
Application.ScreenUpdating = False
Set c = wsData.Cells(Rows.Count, "B").End(xlUp).Offset(1) 'start here
For Each ws In wb.Worksheets
If ws.name <> wsData.Name Then
With ws.Range("I106:I160")
c.Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
Set c = c.offset(0, 1)'next column
End If
Next
Application.ScreenUpdating = True
End Sub
推荐阅读
- javascript - 将threejs网格包裹在另一个网格上
- webpack - JSON 文件包含在包中
- java - 应用程序在 AWT 线程进行本机调用以更新游标时崩溃
- react-native - 在 React Native 中使用 Paytm 支付导致问题
- c++ - 在给定的字符串集中查找常见字符的数量?
- javascript - 如何在threejs中计算3d对象位置并将对象放置在场景中以使多个3d对象不相互重叠
- github - 本地 Jekyll 无法生成正确的 RSS 提要
- php - 如何在 Html 表中用第二行的第二列减去第一行的第一列
- react-native - React Native 更改图片来源
- python - 蟒蛇新手。想知道是否有人可以检查我的代码是否解决了问题