简体   繁体   English

复制范围工作表1粘贴到活动单元格工作表2中

[英]Copy Range Sheet1 Paste in Active Cell Sheet 2

I'm trying to accomplish the following: 我正在尝试完成以下任务:

  1. Sheet1: User clicks a button that runs VBA. Sheet1:用户单击运行VBA的按钮。

  2. Sheet2: VBA selects the first non-blank cell on column D 表格2:VBA选择D列上的第一个非空白单元格

    Range("D" & Rows.Count).End(xlUp).Offset(1).Select Range(“ D”&Rows.Count).End(xlUp).Offset(1).Select

  3. Sheet1: VBA copies a range of values 工作表1:VBA复制一系列值

    Worksheets("Sheet1").Range("E2:AJ11").Copy 工作表( “工作表Sheet1”)的范围。( “E2:AJ11”)。复制

  4. Sheet2: VBA pastes the copied range into the active cell selected previously. Sheet2:VBA将复制的范围粘贴到先前选择的活动单元格中。

This part where I try pasting into the active cell is not working: 我尝试粘贴到活动单元格中的这一部分不起作用:

Worksheets("Results").ActiveCell.PasteSpecial xlPasteValues

Does anyone know how to fix this? 有谁知道如何解决这一问题?

Thanks much! 非常感谢!

Your code could use some refining, but to keep your code and make it work I would change the order of commands to this and see if that works for you. 您的代码可以使用一些改进,但为了保留您的代码并使之正常工作,我将更改命令顺序,以查看是否适合您。

  1. Sheet1: User clicks a button that runs VBA. Sheet1:用户单击运行VBA的按钮。
  2. Sheet1: VBA copies a range of values 工作表1:VBA复制一系列值
  3. Worksheets("Sheet1").Range("E2:AJ11").Copy 工作表( “工作表Sheet1”)的范围。( “E2:AJ11”)。复制

then to sheet 2 然后到表2

  1. Sheet2: VBA selects the first non-blank cell on column D 表格2:VBA选择D列上的第一个非空白单元格
  2. Range("D" & Rows.Count).End(xlUp).Offset(1).Select (or just paste instead of select) Range(“ D”&Rows.Count).End(xlUp).Offset(1).Select (或只是粘贴而不是select)
  3. Sheet2: VBA pastes the copied range into the active cell selected previously. Sheet2:VBA将复制的范围粘贴到先前选择的活动单元格中。

or just skip the line that is bothering you and instead use: 或者只是跳过打扰您的行,而是使用:

Range("D" & Rows.Count).End(xlUp).Offset(1).pastespecial xlpastevalues

(adjust as you need, this is for values) (根据需要进行调整,这是针对值的)

Or use something like this: 或使用像这样的东西:

Sub Copy()

Dim LastRow As Long
Dim Results As Worksheet

    Set Results = Sheets("Results")
    LastRow = Results.Cells(Results.Rows.Count, "D").End(xlUp).row

    Range("E2:AJ11").Copy
    Results.Range("D" & LastRow + 1).PasteSpecial xlPasteAll

    Application.CutCopyMode = False
End Sub

Try this one. 试试这个。

Dim i as Integer
i = 1

Do while cells(i,4) <> ""
    Range("D" & Rows.Count).End(xlUp).Offset(1).Select
    Worksheets("Sheet1").Range("E2:AJ11").Copy
    i = i + 1
Loop

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

相关问题 复制范围表1粘贴到所选单元格表2中 - Copy range sheet1 paste in selected cell sheet 2 从Sheet1复制范围并将其粘贴到Sheet 2中 - Copy Range from Sheet1 And paste it in Sheet 2 从 Sheet1 复制使用的范围并粘贴到 Sheet3 - Copy Used Range from Sheet1 and paste into Sheet3 如果单元格的颜色为绿色,则从 Sheet1 复制一行并将其粘贴到 Sheet 2 - Copy a row from Sheet1 and paste it into Sheet 2 if color of a cell is green 从“ sheet1”上的单元格区域复制到“ sheetB3”上的相同区域 - Copy from cell range on 'sheet1' to same range on 'sheetB3' 将范围从工作表1复制到工作表2 - Copy a range from sheet1 to sheet2 搜索范围Sheet1对Sheet2中的范围根据横向单元格中的值复制到Sheet3 - Searching Range Sheet1 Against Range in Sheet2 Copy to Sheet3 depending on value in lateral cell 将 sheet2 第一行的最后一列与 sheet1 的 F2 单元格进行比较,如果匹配,则显示 msgbox,否则将 F2 范围粘贴到 sheet2 - Comparing last column of first row in sheet2 with F2 cell of sheet1 if it matches then show msgbox or else copy F2 range paste to sheet2 如何完全限定要从Sheet1复制并粘贴到Sheet2的范围? - How to fully qualify a range to copy from Sheet1 and paste to Sheet2? 根据条件从Sheet1复制多个Range并将其粘贴到Sheet2的Sideside中 - Copy multiple Range from Sheet1 based on a conditionand paste it in Alongside in Sheet2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM