excel - 如何复制超出范围的数据
问题描述
我正在尝试从我使用两个字符串设置的范围中复制一些作为列的数据。范围在“B”列中设置,我需要将“C”和“D”列中的数据复制到范围的长度,并将它们粘贴到“B”和“C”列中的另一张表中。
该范围是通过查找两个字符串“实施阶段的初始项目 ER”和“25 年的初始项目 ER”来设置的。
到目前为止,我已经设法编写将数据复制到正确位置的代码,但它只是复制范围(列“B”)中的数据
fr = "Originating Project ERs at Implementation Stage"
fc = "Originating Project ERs at 25"
Set r = Worksheets("Sheet1").Cells.Find(What:=fr, LookAt:=xlWhole)
Set c = Worksheets("Sheet1").Cells.Find(What:=fc, LookAt:=xlWhole)
If Not r Is Nothing Then
StartR = r.Row + 1
Else: MsgBox fr & " not found"
End If
If Not c Is Nothing Then
EndR = c.Row - 1
Else: MsgBox fc & " not found"
End If
If r.Row And c.Row > 1 Then
Worksheets("Sheet1").Range(r, c).Offset(1,1).Copy
Worksheets("PriorityProgress").Range("B2").PasteSpecial Paste:=xlPasteValues
Worksheets("priorityProgress").Range("C2").PasteSpecial Paste:=xlPasteValues
End If`
这是一些示例数据,显示了我想要达到的目标https://i.stack.imgur.com/5csrZ.png
编辑:我已经设法使用 OffSet 1,1 在“C”列中显示第一组记录,现在只需要“D”
解决方案
设法通过单独偏移每一列来解决它
If r.Row And c.Row > 1 Then
Worksheets("Sheet1").Range(r, c).Offset(1, 1).Copy
Worksheets("PriorityProgress").Range("B2").PasteSpecial Paste:=xlPasteValues
Worksheets("Sheet1").Range(r, c).Offset(1, 2).Copy
Worksheets("priorityProgress").Range("C2").PasteSpecial Paste:=xlPasteValues
推荐阅读
- asp.net-mvc - MiniProfiler 未加载,因为未找到探查器路由
- python - wxPython面板未显示
- java - Android:如何给 LinearLayout 一个最大宽度?
- android - android屏幕右侧的工作表
- laravel - 将 api 与真实设备颤振连接起来
- node.js - NODE JS - 从获取的行中形成 JSON 对象
- sql-server - 添加条件唯一检查约束?
- reactjs - 是否有直接从 Firestore 数据库读取的替代方法?
- javascript - 如果选择器不可用(Puppeteer)
- javascript - 将 JavaScript 模块的函数暴露给整个 HTML 文档