Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 复制和粘贴范围取决于条件_Vba_Excel - Fatal编程技术网

Vba 复制和粘贴范围取决于条件

Vba 复制和粘贴范围取决于条件,vba,excel,Vba,Excel,在过去的几天里,我一直在努力编写能够完成以下任务的宏: 1.从一张纸上复制特定单元格是否复制取决于条件 2.将它们粘贴到指定的表格中,其名称由公式加密到指定的单元格中,它们也由公式指定 不幸的是,我无法粘贴图像,因此我将尝试通过粘贴带有问题的代码草图来解释我正在尝试做什么。如果这个含糊不清,请让我知道 Sub The_One() ' For Each c In Worksheets("fsr").Range("O:O") If c.Value = "p" Then 'Now I

在过去的几天里,我一直在努力编写能够完成以下任务的宏: 1.从一张纸上复制特定单元格是否复制取决于条件 2.将它们粘贴到指定的表格中,其名称由公式加密到指定的单元格中,它们也由公式指定

不幸的是,我无法粘贴图像,因此我将尝试通过粘贴带有问题的代码草图来解释我正在尝试做什么。如果这个含糊不清,请让我知道

Sub The_One()
'
For Each c In Worksheets("fsr").Range("O:O")
    If c.Value = "p" Then
    'Now I do not know how to make Excel copy the cells from current row from columns E,F,G,H
    'Now I would like to add cells into the worksheet which name is sepcified by the formula from column P.
    'Inserted cells should be added into a row given by the formula in column Q.
    'I imagine it like that:
        Sheets("group1").Select 'This "group1" cannot be simply tiped into the code, it should be taken from Column P in worksheet("fsr")
        Range("A3:I3").Select 'As above, the range should be specified more like that:
                              'Range("A[row number given by a formula in column Q in Worksheet("fsr")]:I[the same number as before]
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            'Now I would like to copy four cells from Worksheet("fsr") they are in the same row as the current cell from above For Each
            'I imagine it somehow like that:
            Range("E'Here I dont know how to define the row number':H'The same problem'").Activate
            ActiveCell.CurrentRegion.Select 'Is CurrentRegion suitable?
            Selection.Copy
            Worksheets("group1").Select 'But this worksheet should be the one that is given by a formula in column P in Worksheet("fsr")
            Range("E'Here I dont know how to define the row number':F'The same problem'").Activate
            ActiveSheet.Paste 'But I dont want to paste it anywhere. It sholud be pasted into the worksheet given by the formula from column P,
                              'into the row given by the formula from column Q, into the columns C,D,E,F. So:
                              'So when the For Each starts to go trough Range("O:O") in Worksheet("fsr") it notices that there is "p" so it should:
                              'copy cells E2:H2 (because this "p" is in the second row) and paste it in the Worksheet("group1") (because this is what
                              'we find in cell P2 into the cells C3:F3 (row 3 because "3" is what we find in Q2)
    End If
Next c
End Sub
我是Stackoverflow的新手,因此我非常感谢大家对我的行为的评论。 我希望你能找一秒钟来帮助我,我真的需要你的帮助。 致以最良好的问候 阿图尔·鲁特科夫斯基

For Each c In Worksheets("fsr").Range("O:O") 
'This will slow your macro as Excel will search all 1048576 rows
'I suggest you define the range of data in another sheet
起始行| 1 结束行| 30

Sub The_One()
startrow = Worksheets("Sheet1").Cells(1,1)
endrow = Worksheets("Sheet1").Cells(2,1)

For x = startrow to endrow
    If Cells(x,"O").Value = "p" Then
        Range("E" & x, "H" & x).Copy
        Worksheets(Cells(x, "P").Value).Cells(Cells(x, "Q").Value, "C").PasteSpecial xlPasteAll
    End If
    Next    
End Sub

你好谢谢你的回复。粘贴链接是指将链接粘贴到外部服务器上的图像,是吗?不管怎么说,我的问题是不是太模糊而无法回答?致以最诚挚的问候,恳请帮助,Artur Rutkowski要找到最后一行,您可以使用以下代码:endrow=RangeO:O.EndxlDown.row非常感谢Siddharth Sawjani!你让我开心!